Created
May 30, 2013 19:54
-
-
Save mwalz/5680630 to your computer and use it in GitHub Desktop.
Mongo Command Line Quick Reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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" : "[email protected]", "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" : "[email protected]", "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