Skip to content

Instantly share code, notes, and snippets.

@prisskreative
Last active October 4, 2017 17:32
Show Gist options
  • Save prisskreative/3830553f76ed60fac453bc12dc3a465a to your computer and use it in GitHub Desktop.
Save prisskreative/3830553f76ed60fac453bc12dc3a465a to your computer and use it in GitHub Desktop.
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' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment