-
-
Save prisskreative/3830553f76ed60fac453bc12dc3a465a to your computer and use it in GitHub Desktop.
mongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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