Searching...
Monday, 10 September 2012

MongoDB Querying

11:12

Below are the Basic queries for Mongodb

Select Database

Show dbs- This will show all the database name
use dbname- This will switch to the dbname database
show collections- List all collection details

Query

db.collectionname.find(); List all documents from collectionname collection.

Insert

db.collectionname.save({ name : "vinu"});Note that MongoDB will implicitly create any collection that doesn’t already exist

Update

collectionname = db.collectionname.findOne( { name : "vinu" } );

collectionname.lastname= "Raj";

db.collectionname.save(collectionname);

Delete

db.collectionname.drop() - remove entire collectionname collection
db.collectionname.remove() - remove all objects
db.collectionname.remove({name: "vinu"})


 

0 comments: