Skip to content

Commit

Permalink
fix(mongoose): add global usePushEach option for easier Mongoose 4.…
Browse files Browse the repository at this point in the history
…x + MongoDB 3.6

Fix #6858
  • Loading branch information
vkarpov15 committed Aug 14, 2018
1 parent 754a4e9 commit 953a846
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,14 @@ function handleAtomics(self, where, delta, data, value) {
value.$__getAtomics().forEach(function(atomic) {
var op = atomic[0];
var val = atomic[1];
if (self.schema.options.usePushEach && op === '$pushAll') {
var usePushEach = false;
if ('usePushEach' in get(self, 'constructor.base.options', {})) {
usePushEach = self.constructor.base.get('usePushEach');
}
if ('usePushEach' in self.schema.options) {
usePushEach = self.schema.options.usePushEach;
}
if (usePushEach && op === '$pushAll') {
op = '$push';
val = { $each: val };
}
Expand Down
17 changes: 17 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ module.exports = function(options) {
return conn;
};

/*!
* ignore
*/

before(function(done) {
module.exports.mongodVersion(function(err, version) {
if (err) {
return done(err);
}
var mongo36 = version[0] > 3 || (version[0] === 3 && version[1] >= 6);
if (mongo36) {
mongoose.set('usePushEach', true);
}
done();
});
});

/*!
* testing uri
*/
Expand Down

0 comments on commit 953a846

Please sign in to comment.