MongoDB
Installation
Section titled “Installation”In ubuntu, add the package mongodb-clients and mongodb-server.
Configuration
Section titled “Configuration”/etc/mongodb.conf holds the server configuration.
bind_ip
Section titled “bind_ip”bind_ip tells the server which interfaces to listen on. It is comma separated.
Client
Section titled “Client”From your shell, run mongo.
Databases
Section titled “Databases”A database holds many collections.
Show databases
Section titled “Show databases”One mongod server may hold many databases.
> show dbsdatabase 0.0625GBexample 0.0625GBexampledb 0.0625GBrover1 0.0625GBDatabase creation
Section titled “Database creation”From the client, to create a ‘example’ database, switch to the database and create a collection by inserting a document.
> use exampleswitched to db example> db.exampleCollection.insert({})WriteResult({ "nInserted" : 1 })Current database
Section titled “Current database”The client has a current database. Run db by itself to find out what it is.
> dbexampleCollections
Section titled “Collections”See collections.
mongodump and mongorestore
Section titled “mongodump and mongorestore”This is used for backing up and restoring documents.
To dump only a single database, use
mongodump -d db_nameThis will create a directory dump/db_name/ with various json and bson files inside it.
When restoring, use the --drop option to drop each collection before repopulating it.
The dump may be restored to another database. Copy the all the files in dump/ to the
target mongodb server. Then restore it to a new database named foo_db.
mongorestore dump/db_name/ --db=foo_db