mongodb Flashcards
how to load up mongo
mongod on command line
mondodb - what is the equivalent of an sql table
collection
mongodb - delete document where category is sandwich
@col.remove({‘category’ => “sandwich”}) # note how it uses same parameters as in find method
mongodb - equivalent of sql column
bson field
mongodb - equivalent of sql primary key
_id field
mongodb - equivalent of sql row
bson document
mongodb - find all emails (a field) with gmail in it
collection.find {:email => /gmail/i }
mongodb - get all unique tags in the system
posts.distinct(‘tags’)
mongodb - how to decide whether to embed an object or not
look at how you work with objects in your software an entity should get its own collection if you frequently work with that entity by itself.
mongodb - what’s wrong with this data structure: {“_id”=>BSON::ObjectId4eeff4dad27d20f1b500011e, “name”=>{“Margaret Nicholson”=>[#data]}}
should be: {“_id”=>BSON::ObjectId4eeff4dad27d20f1b500011e, “name”=>”Margaret Nicholson” “data”=>[]} why? easier access with queries (db.facebook_likes.find{name:/Margaret/})
mongodb - why don’t you need a created_at column
since the _id includes a timestamp thus this is chronological order posts.find.sort( [[‘_id’, -1]] )
mongodb posts.find( :tags => ‘mongo’ ) add an index to make this more efficient
posts.create_index(‘tags’)