1. Mongodb

CRUD Operation In mongodb

create command in mongodb

db.students.insert({name: 'deepak', age: 10 , class:'3rd'});

or

db.students.save({name: 'deepak', age: 10});

save command is used for if a document already exists with that_id it will be updated instead of being added as new

Read command in mongodb

Query for all the data in the students collection that have a name field with a value of ‘Tom’:

db.students.find({name: 'Tom'})

Update command in mongodb

db.students.update({name: 'sam'}, {age: 29, name: 'sam'})

If you are update a single field of a document. In this case of age and name or class:

update age for the students

db.students.update({name: 'Tom'}, {$set: {age: 29}})

update name for the students

db.students.update({name: 'Tom'}, {$set: {name: 'harry'}})

delete command in mongodb

Deletes all database matching the query parameter:

db.students.deleteOne({name: 'Deepak'})

or

db.students.remove({name: 'sam'}, true)

When You use remove() method. If you execute this command without any argument or without empty argument it will remove all database from the collection.

If you like this post, don’t forget to share 🙂

This article is written by our awesome writer
Comments to: CRUD Operation In mongodb

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories

About

Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page

Login

Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
  •  
    Strength indicator
  •  
  •  
    Log In | Lost Password