MongoDB CRUD – Opensite - Digital Solutions Agency

0422 374 731 info@opensite.com.au

MongoDB CRUD

Last update:

Tutorials ,

Create a Database

// list databases
show db

// display current database
dbs

// create a database
use db_name

CRUD Commands

http://docs.mongodb.org/manual/core/crud-introduction/

Create

// save one user
db.users.save({ 'name': 'Clint' });

// save multiple users
db.users.save({ 'name': 'Clint' }, { 'name': 'John' });

Read

// show all users
db.users.find();

// find a specific user
db.users.find({'name': 'Clint'});

Update

db.users.update({'name': 'Clint'}, {'name': 'Clinton'});

Note: Editing even a single property of an object overwrites all other properties.

Delete

// remove all
db.users.remove({});
// remove one 
db.users.remove({ name: 'Clinton' });

GUI Option

Although it’s easy enough to use the CLI, there’s also a GUI called Robo 3T. Find it here!