How can I save multiple documents concurrently in Mongoose/Node.js?

后端 未结 13 1934
南笙
南笙 2020-12-07 10:20

At the moment I use save to add a single document. Suppose I have an array of documents that I wish to store as single objects. Is there a way of adding them all with a si

13条回答
  •  醉酒成梦
    2020-12-07 10:56

    This is an old question, but it came up first for me in google results when searching "mongoose insert array of documents".

    There are two options model.create() [mongoose] and model.collection.insert() [mongodb] which you can use. View a more thorough discussion here of the pros/cons of each option:

    Mongoose (mongodb) batch insert?

提交回复
热议问题