Since the mongodb upgraded to 3.6 and dropped all support for $pushAll
, Would there be any possible way to set usePushEach on by default for all schemas?
Node 8,
Mongoose 4.13.7
Mongodb 3.6
Should be able to do it with a one liner:
mongoose.plugin(schema => { schema.options.usePushEach = true });
We'll be releasing 5.0.0-rc0 soon, which will remove the dependency on $pushAll
for good.
mongoose.plugin(schema => { schema.options.usePushEach = true });
where should this go??
@dhazlettjr right after you require mongoose will work.
const mongoose = require('mongoose');
mongoose.plugin(schema => { schema.options.usePushEach = true });
const mySchema = new mongoose.Schema({ stuff: String });
const Model = mongoose.model('model', mySchema);
const otherSchema = new mongoose.Schema({ otherStuff: String });
const OtherModel = mongoose.model('other', otherSchema);
This will apply the plugin to all future schema as documented here
Guys, it worked for me... I have no Idea what is mongoose.plugin(schema => { schema.options.usePushEach = true }); but it works ;-)
Thanks a lot....
Since the mongodb upgraded to 3.6 and dropped all support for $pushAll, Would there be any possible way to set usePushEach with Heroku (using mLab add-on for DB).
I am using Heroku for my application. I am not sure where to provide this.
@ffbeatsolutions676 doesn't matter if you're using heroku or not, the below code should work.
const mongoose = require('mongoose');
mongoose.plugin(schema => { schema.options.usePushEach = true });
Thank you, I've pulling my hair out try to find a solution for this issue.
Most helpful comment
Should be able to do it with a one liner:
We'll be releasing 5.0.0-rc0 soon, which will remove the dependency on
$pushAll
for good.