What's the difference between insert(), insertOne(), and insertMany() method?

前端 未结 4 1379
天命终不由人
天命终不由人 2020-12-03 00:15

What\'s the difference between insert(), insertOne(), and insertMany() methods on MongoDB. In what situation should I use each one?

4条回答
  •  不知归路
    2020-12-03 00:53

    There is also a difference in error handling, check here. The insert command returns a document in both success and error cases. But the insertOne and insertMany commands throws exceptions. Exceptions are easier to handle in code, than evaluating the returned document to figure out errors. Probably the reason why they are deprecated in the drivers as mentioned in sstyvane's answer.

提交回复
热议问题