24 2010 19:47:11 GMT-0700 (PDT)", text: "Destination Moon", tags: [ "comic", "adventure" ] } Notes: • _id must be unique, but can be anything you’d like • Default BSON ObjectId if one is not supplied Find the document
$slice operator to return subset of array - some queries hard e.g. find latest comments across all documents - Embedded tree - Single document - Natural - Hard to query
$slice operator to return subset of array - some queries hard e.g. find latest comments across all documents - Embedded tree - Single document - Natural - Hard to query - Normalized (2 collections) - most flexible - more queries
: [ ObjectId("4c4ca25433fb5941681b912f"), ObjectId("4c4ca25433fb5941681b92af”] } categories: { _id : ObjectId("4c4ca25433fb5941681b912f"), name : "adventure" } // All products for a given category > db.products.find({ category_ids : ObjectId("4c4ca25433fb5941681b912f") }) Alternative
Ensure that each job is started once and only once { inprogress : false, priority : 1, message : “Rich documents FTW!”, ... } // find highest priority job and mark as in-progress job = db.jobs.findAndModify({ query : { inprogress : false }, sort : { priority: -1 }, update : { $set : { inprogress : true, started : new Date() } } })
principles remain the same Focus on how the app manipulates data Rapidly evolve schema to meet your requirements Enjoy your new freedom, use it wisely :-)