Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@naxhh
Created October 29, 2012 12:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save naxhh/3973328 to your computer and use it in GitHub Desktop.
Save naxhh/3973328 to your computer and use it in GitHub Desktop.
Useful mongo-shell-admin commands
# Login admin
> use admin
> db.auth('user','pass')
#Basic shows
> show dbs
> show collections
> db.collection.getIndexes()
#Create Index
> db.collection.ensureIndex({ field:1, field2:-1 })
#Delete Index
> db.collection.dropIndex("index_name") (or fields in object)
#Import data
mongoimport --db <db> -c <coll> < <file.json>
#If you exported a entireDB (/folder/*.bson) use:
mongorestore -d <db>--directoryperdb </path/folder>
#Export data
Mongo doesn't have a limit for export... a query needs to be done.
mongoexport --db <db> -c <col> -o <file> [-q <query> (--jsonArray / --csv) ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment