Search code examples
mongodbsails.jssails-mongo

How to perform a bulk insert via sails-mongo and sails.js?


Is there a way to perform a bulk insert via sails-mongo. So if I pass an array of documents to the model's create method, it will insert each document within that array atomically into the database?


Solution

  • It works exactly like you asked:

    Model.create([{foo: "first},{foo:"2nd"}]).exec(...
    

    See http://beta.sailsjs.org/#/documentation/reference/Models/Model-Methods/create.html