mongo
// server
sudo mongod
// mongo consola
mongo
show dbs
-----------
mongo
sudo mkdir -p /data/db
sudo chmod -R 775 /data/db
---------
sudo mongod
---------
// Run mongo db
mongod
// Run console
mongo
// show databases
show dbs
// show current database
db
// Creating database
use db_name
-----------
CRUD Commands
Create
// save one user
$ db.users.save({ name: 'Chris' });
// save multiple users
$ db.users.save([{ name: 'Chris'}, { name: 'Holly' }]);
By saving a document into the users collection of the database you are currently in, you have successfully created both the database and collection if they did not already exist.
Read
// show all users
$ db.users.find();
// find a specific user
$ db.users.find({ name: 'Holly' });
Update
db.users.update({ name: 'Holly' }, { name: 'Holly Lloyd' });
Delete
// remove all
db.users.remove({});
// remove one
db.users.remove({ name: 'Holly' });