NoSQL

MongoDB

Commands

Start it
mongo
Show databases
show dbs
Select a database
use database
List tables (collections)
show collections
Show content from a collection (table)
db.<collection>.find().pretty()
Passing parameters (greater than/equal)
db.<collection>.find({ age: { $gte: 18 } })
Limit results (first five)
db.users.find().limit(5)
Dump a database
mongodump --db <database_name> --out <backup_directory>
Dump a collection
mongodump --db myDatabase --collection myCollection --out /path/to/backup/
codeshe
  • Mongo dump the data in binary form, creating BSON files, in order to convert then is a readable form use:

bsondump <input_bson_file>
  • It's possible also to restore a database from a dump file with:

mongorestore --db <database_name> <path_to_backup>

Last updated