How to stop insertion of Duplicate documents in a mongodb collection

后端 未结 4 1846
孤城傲影
孤城傲影 2020-11-30 01:26

Let us have a MongoDB collection which has three docs..

db.collection.find()

 { _id:\'...\', user: \'A\', title: \'Physics\',   Bank: \'         


        
4条回答
  •  一个人的身影
    2020-11-30 02:29

    It has been updated from the above answers.

    please use db.collection.updateOne() instead of db.collection.update(). and also db.collection.createIndexes() instead of db.collection.ensureIndex()

    Update: the methods update() and ensureIndex() has been deprecated from mongodb 2.*, you can see more details in mongo and the path is ./mongodb/lib/collection.js. For update(), the recommend methods are updateOne, updateMany, or bulkWrite. For ensureIndex(), the recommend method is createIndexes.

提交回复
热议问题