MongoDB Querying

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"})


 

No comments:

Post a Comment

12 classic String-based Java interview questions with simple explanations and code.

  1️⃣ Check if a String is a Palindrome Problem Given a string, check if it reads the same forward and backward. Example: "madam...

Featured Posts