How is insertMany different from collection.insert in Mongoose?

I turned around to find the right solution to insert a large number of documents into MongoDB using Mongoose.

My current solution looks like this:

MongoClient.saveData = function(RecordModel, data, priority, SCHID, callback){ var dataParsed = parseDataToFitSchema(data, priority, SCHID); console.log("Model created. Inserting in batches."); RecordModel.insertMany(dataParsed) .then(function(mongooseDocuments) { console.log("Insertion was successful."); }) .catch(function(err) { callback("Error while inserting data to DB: "+err); return; }) .done(function() { callback(null); return; }); } 

But it seems to me that there are other proposed solutions. Like this one: http://www.unknownerror.org/opensource/Automattic/mongoose/q/stackoverflow/16726330/mongoose-mongodb-batch-insert

Using collection.insert . How is this different from Model.insertMany ?

The same goes for updating, my previous question: What is the correct approach to updating many records in MongoDB using Mongoose

asks how to update a large chunk of data using Mongoose, defined by _id . The answer is to use collection.bulkWrite while I am impressed with Model.insertMany too.

+2
mongodb mongoose
Aug 04 '16 at 8:23
source share

No one has answered this question yet.

See similar questions:

21
What is the difference between the insert (), insertOne () and insertMany () methods?
17
What is the correct approach to updating many records in MongoDB using Mongoose
10
MongoDB: Bulk insert (Bulk.insert) vs insert multiple (insert ([...]))

or similar:

3044
What is the difference between tilde (~) and carriage (^) in .json package?
2237
How to pass command line arguments to Node.js?
2201
How to decide when to use Node.js?
1822
What is the difference between dependencies, devDependencies and peerDependencies in the npm package.json file?
1648
How to quit Node.js
28
Mongoose - RangeError: maximum call stack size exceeded
four
Mongoose object id is null
one
Mongoose update many don't work with $ cond in node.js
one
Mongoose pre.remove middleware objects in an array is never called
0
How to return from a search in nodejs, mongoose mongodb collections



All Articles