Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

I want to know what is the exact difference between "save" and "insert" command in MongoDB? For me, both syntaxes look the same:

db.users.save({username:"google",password:"google123"})

db.users.insert({username:"google",password:"google123"})

Please guide me:-)

1 Answer

0 votes
by (107k points)
edited by

The instances that you have provided, the action for both save and insert is essentially the same because as the document provided in 'save' has no _id field.

But the main difference between 'save' and 'insert' command is that the 'save' command can insert or update a document whereas 'insert' only performs the insertion.

Do you want to be a full-stack developer? Enroll in this Full Stack Certification to get started with your journey.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked Oct 16, 2019 in Web Technology by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...