Mongoose: what's the differences between Model.create and Collection.insert
In Mongoose, there is Model.create
and Collection.insert
(the latter isn't strictly part of Mongoose, but of the underlying MongoDB driver).
According to the Mongoose developer, they are basically the same when called with an array of documents, although looking at the code makes me think that there are subtle differences (warning: I haven't looked at the code that well so I might be mistaken about the following):
- using
Model.create
will call any validators/hooks declared on your schema; Model.create
does a.save
for each document in the array, resulting inN
database calls (whereN
is the number of documents in the array);Collection.insert
performs one large database call;