Web
Analytics
update , remove and drop queries in mongodb | Angular | ASP.NET Tutorials

For Consultation : +91 9887575540

Stay Connected :

update , remove and drop queries in mongodb

Following command will update only single document(Default behaviour)
db.info.update({},{$set : { age : 40 }})
Following command will update only Multiple document
db.info.update({},{$set : { age : 40 }} , {multi : true})
Update Only single document using following command
db.info.update({name : “yogeshdotnet1”},{$set : { age : 40 }} , {multi : true})
if we want to unset any documents(Following will remove age from all documents)
db.info.update({},{$unset : { age : }} , {multi : true})
Replace document using update
db.info.update({name : “yogeshdotnet1”},{address: “Pratap Nagar”} )
Remove document
db.info.remove({name : “yogeshdotnet1”})
Remove all documents
db.info.remove({})
To drop a collection
db.info.drop();