Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 212011
 

Update an existing document in MongoDB

Answer:

In an given collection, if you want to perform update on an existing document, the easiest way is to use the following commands.

employee = db.employees.findOne( { name : "Peter" } );
employee.position = "Project Manager";
db.employees.save( employee );

Done.

Apr 072011
 

Drop a collection in MongoDB

Answer:

To drop a collection in MongoDB, enter the interactive shell, and type:

db.foo.drop()

If you want to remove all the objects only, not dropping the collection, try

db.foo.remove()