Skip to content

Instantly share code, notes, and snippets.

@mwalz
Created May 30, 2013 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwalz/5680630 to your computer and use it in GitHub Desktop.
Save mwalz/5680630 to your computer and use it in GitHub Desktop.
Mongo Command Line Quick Reference
## Mongo CLI commands I don't use often enough to remember
## select database to use
use db_name
## list 'tables'
show collections
## list table contents
db.table_name.find()
## insert new 'row' into table
db.table_name.insert({"otherObj" : ObjectId("51012"), "email" : "f@f.co", "name" : "Joe", "id" : 123, "zip" : "12345" })
## update 'row' into table
## '{$set: {}}' updates, '{"val" : "new"}' (without the {$set: } wrapper) replaces all values.
db.table_name.update({ "_id" : ObjectId("51013") }, {$set: {"otherObj" : ObjectId("51012"), "email" : "f@f.co", "name" : "Joe", "id" : 456, "zip" : "12345" }})
## remove 'row' from table
db.table_name.remove({"_id" : ObjectId("51013")})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment