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?
How to perform a bulk insert via sails-mongo and sails.js?
Asked Answered
I have tried passing the array directly into Model.create() (with Model being the name of my given model) and I have also tried Model.createEach()... it just indexes it as an actual array, rather than as each document in the array as you would expect from a batch insert with mongodb –
Trimetric
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
Does this only work in the beta version, or will it work in stable version (0.9.x)? –
Trimetric
This looks great. Will it also work for Model.findOrCreate() ? If so what would be the syntax? Thanks –
Supper
@KevinBaker: Yes - see: sailsjs.org/#/documentation/reference/waterline/models/…. You can use several records or criteria –
Cleft
© 2022 - 2024 — McMap. All rights reserved.