MongoDB
Revision as of 12:36, 25 February 2016 by Rafahsolis (talk | contribs)
Installation
Ubuntu 14.04
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list sudo apt-get update sudo apt-get install -y mongodb-org # Specific version install: sudo apt-get install -y mongodb-org=3.2.1 mongodb-org-server=3.2.1 mongodb-org-shell=3.2.1 mongodb-org-mongos=3.2.1 mongodb-org-tools=3.2.1
Start/Stop/Restart MongoDB
sudo service mongod start | stop | restart
Verify that MongoDB has started successfully
Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
Guides
Getting Started
Before deploying MongoDB in a production environment
Manage user accounts and roles
Data directories
/var/log/mongodb /var/lib/mongodb
Create Database
use DATABASE_NAME
Show databases
show dbs
db.adminCommand('listDatabases')
db.getMongo().getDBNames()
- To view databases they must have data
To show the current database type:
db
Insert
db.COLLECTION_NAME.insert({"name":"data1"})
Get Colection Names
db.getCollectionNames()
Query
db.COLLECTION_NAME.find()
db.COLLECTION_NAME.find({"name": "data1"})