Skip to content

Instantly share code, notes, and snippets.

@ncl0w
Forked from naxhh/Mongo utilities
Created June 27, 2017 00:20
Show Gist options
  • Save ncl0w/390298248906698e0505e288192e997d to your computer and use it in GitHub Desktop.
Save ncl0w/390298248906698e0505e288192e997d 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