Articles → MONGODB → Ordered Insert In Mongodb

Ordered Insert In Mongodb

What Are Ordered Insert?

Picture showing how the ordered insert works in insertmany function
Click to Enlarge

What Will Happen If An Error Occurs During Insert?

db.Articles.insertMany([{_id:4, subject:'subject4'}, {_id:2, subject:'subject2'}, {_id:5, subject:'subject5'}])

Picture showing the error message when trying to insert duplicate _id in the document
Click to Enlarge

Picture showing the data added in the document
Click to Enlarge

Disabling The Ordered Insert

db.Articles.insertMany([{_id:5, subject:'subject5'}, {_id:2, subject:'subject2'}, {_id:6, subject:'subject6'}], {ordered:false})   

Picture showing the duplicate error message when orderd insert is disabled
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Saturday, October 28, 2023


Your Email Id  
Query/FeedbackCharacters remaining 250