SlideShare a Scribd company logo
Simple e-commerce schema
Christian Kvalheim @christkv
Agenda
• The product
• The categories
• Product by categories
• Category navigation
• The cart
• Add product to cart
• Remove product from cart
• Expire cart
• The checkout
The product
 {
     sku: "111445GB3",
     title: "Simsong One mobile phone",
     description: "The greatest Onedroid phone on the market .....",

     manufacture_details: {
        model_number: "A123X",
        release_date: new ISODate("2012-05-17T08:14:15.656Z")
     },
     shipping_details: {
        weight: 350,
        width: 10,
        height: 10,
        depth: 1
     },
     quantity: 99,
     pricing: {
        price: 1000
     }
 }
The product, add categories
db.products.update(
  {sku: "111445GB3"},
  {$set: { categories: ['mobile/15G', 'mobile/fm'] }});


  {
    sku: "111445GB3",
    title: "Simsong One mobile phone",
    description: "The greatest Onedroid phone on the market .....",
    manufacture_details: {
       model_number: "A123X", release_date: new
  ISODate("2012-05-17T08:14:15.656Z")
    },
    shipping_details: {
       weight: 350, width: 10, height: 10, depth: 1
    },
    quantity: 99,

   categories: ['mobile/15G', 'mobile/
  fm'],
The product, add categories
• Add an index on the categories
db.products.ensureIndex({categories:1 })



• Locate all the products in a category
db.products.find({categories: /^mobile/fm/})



• If we use case sensitive pre-fix regular expressions
  we use the btree index and have very fast lookups
Categories
  {
      title: "Mobiles containing a FM radio",
      parent: "mobile",
      path: "mobile/fm"
  }


db.categories.insert({title: "Mobiles containing a FM radio", parent:
"mobile", path: "mobile/fm"})

db.categories.insert({title: "Mobiles with 15G support", parent:
"mobile", path: "mobile/15G"})

db.categories.ensureIndex({parent: 1, path: 1})

db.categories.ensureIndex({path: 1})
Categories, queries
• Locate all categories directly under /mobile
db.categories.find({parent: /^mobile/}, {_id: 0, path: 1})



• Locate all the categories under /mobile
db.categories.find({path: /^mobile/}, {_id: 0, path: 1})
Adding to Cart
Cart, example schema
{
    _id: "the_users_session_id",
    status:'active'

    quantity: 2,
    total: 2000,

    products: []
}


• Add item to cart
• Update inventory only if we have enough quantity
• Rollback if inventory update fails
Cart, add item to cart
    db.carts.update({
        _id: "the_users_session_id", status:'active'
      }, {
        $set: { modified_on: ISODate() },
        $push: {
           products: {
             sku: "111445GB3", quantity: 1, title: "Simsong One mobile
    phone", price:1000
           }
        }
      });

{
  _id: "the_users_session_id",
  status:'active'
  quantity: 2,
  total: 2000,
  products: [{sku: "111445GB3", quantity: 1, title: "Simsong One mobile
phone", price:1000}]
}
Cart, add to cart, inventory cover
  db.products.update({
      sku: "111445GB3", quantity: {$gte: 1}
    }, {
      $inc: {quantity: -1},
      $push: {
         in_carts: {
           quantity:1, id: "the_users_session_id", timestamp: new
  ISODate()
         }
      }

• If we did not update the stock, roll back cart add
if(!db.runCommand({getLastError:1}).updatedExisting) {
  db.carts.update({
       _id: "the_users_session_id"
    }, {
       $pull: {products: {sku:"111445GB3"}}
    })
}
Update Cart
Cart, update quantity
  db.carts.update({
       _id: "the_users_session_id", "products.sku": "111445GB3", status:
  "active"
    }, {
       $set: {
           modified_on: new ISODate(),
           "products.$.qty": new_quantity
         }
    })



• Update the quantity in the cart
 • new_quantity = 2
 • old_quantity = 1
 • delta_quantity = new_quantity - old_quantity
Cart, update inventory
  db.products.update({
       sku: "111445GB3",
       "in_carts.id": "the_users_session_id",
       quantity: {
         $gte: 1
       }
    }, {
       $inc: { quantity: (-1)*delta_quantity },
       $set: {
         "in_carts.$.quantity": new_quantity, timestamp: new ISODate()
       }
    })

• Attempt to update the inventory
 • new_quantity = 2
 • old_quantity = 1
 • delta_quantity = new_quantity - old_quantity
Cart, on failure rollback
  if(!db.runCommand({getLastError:1}).updatedExisting) {
    db.carts.update({
         _id: "the_users_session_id", "products.sku": "111445GB3"
      }, {
         $set : { "in_carts.$.quantity": old_quantity}
      })
  }




• If the update fails roll back the cart to the previous
  quantity
 • new_quantity = 2
 • old_quantity = 1
 • delta_quantity = new_quantity - old_quantity
Expire Carts
Cart, expire all the carts
 var carts = db.carts.find({status:"expiring"})
 for(var i = 0; i < carts.length; i++) {
   var cart = carts[i]

     for(var j = 0; j < cart.products.length; j++) {
       var product = cart.products[i]

         db.products.update({
              sku: product.sku,
              "in_carts.id": cart._id,
              "in_carts.quantity": product.quantity
           }, {
              $inc: {quantity: item.quantity},
              $pull: {in_carts: {id: cart._id}}
           })
     }

     db.carts.update({
          _id: cart._id,
          $set: {status: 'expired'}
       })
 }
Checkout
Insert an Order
 db.orders.insert({
    created_on: new ISODate("2012-05-17T08:14:15.656Z"),
    shipping: {
       customer: "Peter P Peterson",
       address: "Longroad 1343",
       city: "Peterburg",
       region: "",
       state: "PE",
       country: "Peteonia",
       delivery_notes: "Leave at the gate",
       tracking: {
          company: "ups", tracking_number: "22122X211SD",
          status: "ontruck",
          estimated_delivery: new ISODate("2012-05-17T08:14:15.656Z")
       },
    },
    payment: { method: "visa", transaction_id: "2312213312XXXTD" }
    products: {
       {quantity: 2, sku:"111445GB3", title: "Simsong mobile phone",
 unit_cost:1000, currency:"USD"}
    }
 })
Cart, finish up and clean up
db.carts.update({
    _id: "the_users_session_id"
  }, {
    $set: {status:"complete"}
  });

• Set the cart status as completed
db.products.update({
    "in_carts.id": "the_users_session_id"
  }, {
    $pull: {in_carts: {id: "the_users_session_id"}}
  }, false, true);


• Remove all carts from products
Thank you and happy
     schemaing
  twitter: @christkv

More Related Content

What's hot

MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
Krishnaprasad k
 
Full Stack Web Development
Full Stack Web DevelopmentFull Stack Web Development
Full Stack Web Development
SWAGATHCHOWDARY1
 
varun ppt.ppt
varun ppt.pptvarun ppt.ppt
varun ppt.ppt
ArunkumarKArun
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
Jaya Naresh Kovela
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
Dhrubaji Mandal ♛
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
Amit Ghosh
 
Designing, Developing & Testing for Accessibility
Designing, Developing & Testing for AccessibilityDesigning, Developing & Testing for Accessibility
Designing, Developing & Testing for Accessibility
Eric Malcolm
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
NDLI PPT.pptx
NDLI PPT.pptxNDLI PPT.pptx
NDLI PPT.pptx
Pethuraj M
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
NAVEENSAGGAM1
 
Arango DB
Arango DBArango DB
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
JohnTaieb
 
Difference Between Angular and AngularJS.pdf
Difference Between Angular and AngularJS.pdfDifference Between Angular and AngularJS.pdf
Difference Between Angular and AngularJS.pdf
Your Team in India
 
Library technology
Library technologyLibrary technology
Library technology
DPerkins123
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
Derek Willian Stavis
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.js
Smile Gupta
 
Java Spring
Java SpringJava Spring
Java Spring
AathikaJava
 
Angular
AngularAngular
Angular
Lilia Sfaxi
 

What's hot (20)

MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
Full Stack Web Development
Full Stack Web DevelopmentFull Stack Web Development
Full Stack Web Development
 
varun ppt.ppt
varun ppt.pptvarun ppt.ppt
varun ppt.ppt
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
Designing, Developing & Testing for Accessibility
Designing, Developing & Testing for AccessibilityDesigning, Developing & Testing for Accessibility
Designing, Developing & Testing for Accessibility
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
NDLI PPT.pptx
NDLI PPT.pptxNDLI PPT.pptx
NDLI PPT.pptx
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Arango DB
Arango DBArango DB
Arango DB
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
Difference Between Angular and AngularJS.pdf
Difference Between Angular and AngularJS.pdfDifference Between Angular and AngularJS.pdf
Difference Between Angular and AngularJS.pdf
 
Library technology
Library technologyLibrary technology
Library technology
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.js
 
Java Spring
Java SpringJava Spring
Java Spring
 
Express node js
Express node jsExpress node js
Express node js
 
Angular
AngularAngular
Angular
 

Similar to Mongo db ecommerce

MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: Keynote
MongoDB
 
Retail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed InventoryRetail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
MongoDB
 
Query for json databases
Query for json databasesQuery for json databases
Query for json databases
Binh Le
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
Chris Saxon
 
RESTful services Design Lab
RESTful services Design LabRESTful services Design Lab
RESTful services Design Lab
Paulo Gandra de Sousa
 
GraphQL: APIs the New Way.
GraphQL: APIs the New Way.GraphQL: APIs the New Way.
GraphQL: APIs the New Way.
EatDog
 
GraphQL - APIs The New Way
GraphQL - APIs The New WayGraphQL - APIs The New Way
GraphQL - APIs The New Way
Vladimir Tsukur
 
Introduction to type classes in 30 min
Introduction to type classes in 30 minIntroduction to type classes in 30 min
Introduction to type classes in 30 min
Pawel Szulc
 
MongoDB World 2019: Just-in-time Validation with JSON Schema
MongoDB World 2019: Just-in-time Validation with JSON SchemaMongoDB World 2019: Just-in-time Validation with JSON Schema
MongoDB World 2019: Just-in-time Validation with JSON Schema
MongoDB
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
Gabriele Lana
 
Introduction to type classes
Introduction to type classesIntroduction to type classes
Introduction to type classes
Pawel Szulc
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
Tomas Jansson
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
CodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigCodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPig
Dusan Zamurovic
 
Webinar: Position and Trade Management with MongoDB
Webinar: Position and Trade Management with MongoDBWebinar: Position and Trade Management with MongoDB
Webinar: Position and Trade Management with MongoDB
MongoDB
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDB
MongoDB
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMongoDB
 
Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days Munich
Norberto Leite
 
GraphQL APIs in Scala with Sangria
GraphQL APIs in Scala with SangriaGraphQL APIs in Scala with Sangria
GraphQL APIs in Scala with Sangria
Vladimir Tsukur
 
Hypermedia API’s
Hypermedia API’s Hypermedia API’s
Hypermedia API’s
3camp
 

Similar to Mongo db ecommerce (20)

MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: Keynote
 
Retail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed InventoryRetail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
 
Query for json databases
Query for json databasesQuery for json databases
Query for json databases
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
 
RESTful services Design Lab
RESTful services Design LabRESTful services Design Lab
RESTful services Design Lab
 
GraphQL: APIs the New Way.
GraphQL: APIs the New Way.GraphQL: APIs the New Way.
GraphQL: APIs the New Way.
 
GraphQL - APIs The New Way
GraphQL - APIs The New WayGraphQL - APIs The New Way
GraphQL - APIs The New Way
 
Introduction to type classes in 30 min
Introduction to type classes in 30 minIntroduction to type classes in 30 min
Introduction to type classes in 30 min
 
MongoDB World 2019: Just-in-time Validation with JSON Schema
MongoDB World 2019: Just-in-time Validation with JSON SchemaMongoDB World 2019: Just-in-time Validation with JSON Schema
MongoDB World 2019: Just-in-time Validation with JSON Schema
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
Introduction to type classes
Introduction to type classesIntroduction to type classes
Introduction to type classes
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
 
CodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigCodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPig
 
Webinar: Position and Trade Management with MongoDB
Webinar: Position and Trade Management with MongoDBWebinar: Position and Trade Management with MongoDB
Webinar: Position and Trade Management with MongoDB
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDB
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodb
 
Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days Munich
 
GraphQL APIs in Scala with Sangria
GraphQL APIs in Scala with SangriaGraphQL APIs in Scala with Sangria
GraphQL APIs in Scala with Sangria
 
Hypermedia API’s
Hypermedia API’s Hypermedia API’s
Hypermedia API’s
 

More from christkv

From SQL to MongoDB
From SQL to MongoDBFrom SQL to MongoDB
From SQL to MongoDB
christkv
 
New in MongoDB 2.6
New in MongoDB 2.6New in MongoDB 2.6
New in MongoDB 2.6
christkv
 
Lessons from 4 years of driver develoment
Lessons from 4 years of driver develomentLessons from 4 years of driver develoment
Lessons from 4 years of driver develoment
christkv
 
Storage talk
Storage talkStorage talk
Storage talkchristkv
 
Cdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupCdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetup
christkv
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
christkv
 
Schema design
Schema designSchema design
Schema design
christkv
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
christkv
 
Node.js and ruby
Node.js and rubyNode.js and ruby
Node.js and ruby
christkv
 

More from christkv (9)

From SQL to MongoDB
From SQL to MongoDBFrom SQL to MongoDB
From SQL to MongoDB
 
New in MongoDB 2.6
New in MongoDB 2.6New in MongoDB 2.6
New in MongoDB 2.6
 
Lessons from 4 years of driver develoment
Lessons from 4 years of driver develomentLessons from 4 years of driver develoment
Lessons from 4 years of driver develoment
 
Storage talk
Storage talkStorage talk
Storage talk
 
Cdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupCdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetup
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Schema design
Schema designSchema design
Schema design
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
 
Node.js and ruby
Node.js and rubyNode.js and ruby
Node.js and ruby
 

Recently uploaded

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 

Recently uploaded (20)

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 

Mongo db ecommerce

  • 2. Agenda • The product • The categories • Product by categories • Category navigation • The cart • Add product to cart • Remove product from cart • Expire cart • The checkout
  • 3. The product { sku: "111445GB3", title: "Simsong One mobile phone", description: "The greatest Onedroid phone on the market .....", manufacture_details: { model_number: "A123X", release_date: new ISODate("2012-05-17T08:14:15.656Z") }, shipping_details: { weight: 350, width: 10, height: 10, depth: 1 }, quantity: 99, pricing: { price: 1000 } }
  • 4. The product, add categories db.products.update( {sku: "111445GB3"}, {$set: { categories: ['mobile/15G', 'mobile/fm'] }}); { sku: "111445GB3", title: "Simsong One mobile phone", description: "The greatest Onedroid phone on the market .....", manufacture_details: { model_number: "A123X", release_date: new ISODate("2012-05-17T08:14:15.656Z") }, shipping_details: { weight: 350, width: 10, height: 10, depth: 1 }, quantity: 99, categories: ['mobile/15G', 'mobile/ fm'],
  • 5. The product, add categories • Add an index on the categories db.products.ensureIndex({categories:1 }) • Locate all the products in a category db.products.find({categories: /^mobile/fm/}) • If we use case sensitive pre-fix regular expressions we use the btree index and have very fast lookups
  • 6. Categories { title: "Mobiles containing a FM radio", parent: "mobile", path: "mobile/fm" } db.categories.insert({title: "Mobiles containing a FM radio", parent: "mobile", path: "mobile/fm"}) db.categories.insert({title: "Mobiles with 15G support", parent: "mobile", path: "mobile/15G"}) db.categories.ensureIndex({parent: 1, path: 1}) db.categories.ensureIndex({path: 1})
  • 7. Categories, queries • Locate all categories directly under /mobile db.categories.find({parent: /^mobile/}, {_id: 0, path: 1}) • Locate all the categories under /mobile db.categories.find({path: /^mobile/}, {_id: 0, path: 1})
  • 9. Cart, example schema { _id: "the_users_session_id", status:'active' quantity: 2, total: 2000, products: [] } • Add item to cart • Update inventory only if we have enough quantity • Rollback if inventory update fails
  • 10. Cart, add item to cart db.carts.update({ _id: "the_users_session_id", status:'active' }, { $set: { modified_on: ISODate() }, $push: { products: { sku: "111445GB3", quantity: 1, title: "Simsong One mobile phone", price:1000 } } }); { _id: "the_users_session_id", status:'active' quantity: 2, total: 2000, products: [{sku: "111445GB3", quantity: 1, title: "Simsong One mobile phone", price:1000}] }
  • 11. Cart, add to cart, inventory cover db.products.update({ sku: "111445GB3", quantity: {$gte: 1} }, { $inc: {quantity: -1}, $push: { in_carts: { quantity:1, id: "the_users_session_id", timestamp: new ISODate() } } • If we did not update the stock, roll back cart add if(!db.runCommand({getLastError:1}).updatedExisting) { db.carts.update({ _id: "the_users_session_id" }, { $pull: {products: {sku:"111445GB3"}} }) }
  • 13. Cart, update quantity db.carts.update({ _id: "the_users_session_id", "products.sku": "111445GB3", status: "active" }, { $set: { modified_on: new ISODate(), "products.$.qty": new_quantity } }) • Update the quantity in the cart • new_quantity = 2 • old_quantity = 1 • delta_quantity = new_quantity - old_quantity
  • 14. Cart, update inventory db.products.update({ sku: "111445GB3", "in_carts.id": "the_users_session_id", quantity: { $gte: 1 } }, { $inc: { quantity: (-1)*delta_quantity }, $set: { "in_carts.$.quantity": new_quantity, timestamp: new ISODate() } }) • Attempt to update the inventory • new_quantity = 2 • old_quantity = 1 • delta_quantity = new_quantity - old_quantity
  • 15. Cart, on failure rollback if(!db.runCommand({getLastError:1}).updatedExisting) { db.carts.update({ _id: "the_users_session_id", "products.sku": "111445GB3" }, { $set : { "in_carts.$.quantity": old_quantity} }) } • If the update fails roll back the cart to the previous quantity • new_quantity = 2 • old_quantity = 1 • delta_quantity = new_quantity - old_quantity
  • 17. Cart, expire all the carts var carts = db.carts.find({status:"expiring"}) for(var i = 0; i < carts.length; i++) { var cart = carts[i] for(var j = 0; j < cart.products.length; j++) { var product = cart.products[i] db.products.update({ sku: product.sku, "in_carts.id": cart._id, "in_carts.quantity": product.quantity }, { $inc: {quantity: item.quantity}, $pull: {in_carts: {id: cart._id}} }) } db.carts.update({ _id: cart._id, $set: {status: 'expired'} }) }
  • 19. Insert an Order db.orders.insert({ created_on: new ISODate("2012-05-17T08:14:15.656Z"), shipping: { customer: "Peter P Peterson", address: "Longroad 1343", city: "Peterburg", region: "", state: "PE", country: "Peteonia", delivery_notes: "Leave at the gate", tracking: { company: "ups", tracking_number: "22122X211SD", status: "ontruck", estimated_delivery: new ISODate("2012-05-17T08:14:15.656Z") }, }, payment: { method: "visa", transaction_id: "2312213312XXXTD" } products: { {quantity: 2, sku:"111445GB3", title: "Simsong mobile phone", unit_cost:1000, currency:"USD"} } })
  • 20. Cart, finish up and clean up db.carts.update({ _id: "the_users_session_id" }, { $set: {status:"complete"} }); • Set the cart status as completed db.products.update({ "in_carts.id": "the_users_session_id" }, { $pull: {in_carts: {id: "the_users_session_id"}} }, false, true); • Remove all carts from products
  • 21. Thank you and happy schemaing twitter: @christkv

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n