Skip to content

Instantly share code, notes, and snippets.

@daniel-roberts-10gen
Created May 21, 2012 14:48
Show Gist options
  • Save daniel-roberts-10gen/2762727 to your computer and use it in GitHub Desktop.
Save daniel-roberts-10gen/2762727 to your computer and use it in GitHub Desktop.
Limited Inventory
//Update if current
db.inventory.insert({sku:'abc',qty:10})
db.inventory.update({sku:'abc'},{$set : {qty:10}})
p = db.inventory.findOne()
db.inventory.update({sku:p.sku,qty:p.qty},{$inc : {qty : -1}})
db.getLastErrorObj()
db.inventory.update({sku:p.sku,qty:p.qty},{$inc : {qty : -1}})
db.getLastErrorObj()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment