I am starting to use MongoDB a lot these days, but keep forgetting the commands, so here is a cheat sheet.
Drop Database
use $DATABASE_NAME
db.dropDatabase()
db.dropDatabase()
Drop collection
use $DATABASE_THAT_HOLDS_COLLECTION
db.$COLLECTION_NAME.drop()
db.$COLLECTION_NAME.drop()
List everything inside a collection
use $DATABASE_THAT_HOLDS_COLLECTION
db.$COLLECTION_NAME.find()
db.$COLLECTION_NAME.find()
Create Database Admin User
use [database name here] db.createUser( { user: "USERNAME GOES HERE", pwd: "PASSWORD GOES HERE", roles: [ "readWrite", "dbAdmin" ] } )
This only works on versions 2.6+ and will not work on 2.4.9
Get Version
Outside of the mongo client run:
mongodb --version
No comments:
Post a Comment