Skip to content

Commit 953a846

Browse files
committed
fix(mongoose): add global usePushEach option for easier Mongoose 4.x + MongoDB 3.6
Fix #6858
1 parent 754a4e9 commit 953a846

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/model.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,14 @@ function handleAtomics(self, where, delta, data, value) {
432432
value.$__getAtomics().forEach(function(atomic) {
433433
var op = atomic[0];
434434
var val = atomic[1];
435-
if (self.schema.options.usePushEach && op === '$pushAll') {
435+
var usePushEach = false;
436+
if ('usePushEach' in get(self, 'constructor.base.options', {})) {
437+
usePushEach = self.constructor.base.get('usePushEach');
438+
}
439+
if ('usePushEach' in self.schema.options) {
440+
usePushEach = self.schema.options.usePushEach;
441+
}
442+
if (usePushEach && op === '$pushAll') {
436443
op = '$push';
437444
val = { $each: val };
438445
}

test/common.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ module.exports = function(options) {
100100
return conn;
101101
};
102102

103+
/*!
104+
* ignore
105+
*/
106+
107+
before(function(done) {
108+
module.exports.mongodVersion(function(err, version) {
109+
if (err) {
110+
return done(err);
111+
}
112+
var mongo36 = version[0] > 3 || (version[0] === 3 && version[1] >= 6);
113+
if (mongo36) {
114+
mongoose.set('usePushEach', true);
115+
}
116+
done();
117+
});
118+
});
119+
103120
/*!
104121
* testing uri
105122
*/

0 commit comments

Comments
 (0)