Skip to content

Commit c4ca444

Browse files
committed
located area of problem
1 parent 6320ed3 commit c4ca444

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

lib/drivers/node-mongodb-native/collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function iter(i) {
9494
NativeCollection.prototype[i] = function() {
9595
const collection = this._getCollection();
9696
const args = Array.from(arguments);
97+
console.log('what is args', args, args[0][0] ? args[0][0].updateOne : '');
9798
const _this = this;
9899
const globalDebug = _this &&
99100
_this.conn &&
@@ -119,7 +120,6 @@ function iter(i) {
119120
throw error;
120121
}
121122
}
122-
123123
let _args = args;
124124
let callback = null;
125125
if (this._shouldBufferCommands() && this.buffer) {

lib/helpers/model/castBulkWrite.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,7 @@ module.exports = function castBulkWrite(originalModel, op, options) {
6666

6767
_addDiscriminatorToObject(schema, op['updateOne']['filter']);
6868

69-
if (model.schema.$timestamps != null && op['updateOne'].timestamps !== false) {
70-
const createdAt = model.schema.$timestamps.createdAt;
71-
const updatedAt = model.schema.$timestamps.updatedAt;
72-
applyTimestampsToUpdate(now, createdAt, updatedAt, op['updateOne']['update'], {});
73-
}
74-
75-
if (op['updateOne'].timestamps !== false) {
76-
applyTimestampsToChildren(now, op['updateOne']['update'], model.schema);
77-
}
69+
7870

7971
const shouldSetDefaultsOnInsert = op['updateOne'].setDefaultsOnInsert == null ?
8072
globalSetDefaultsOnInsert :
@@ -96,11 +88,23 @@ module.exports = function castBulkWrite(originalModel, op, options) {
9688
strict: strict,
9789
upsert: op['updateOne'].upsert
9890
});
99-
91+
console.log('what is op before', op);
92+
// problem is here
10093
op['updateOne']['update'] = castUpdate(model.schema, op['updateOne']['update'], {
10194
strict: strict,
10295
upsert: op['updateOne'].upsert
10396
}, model, op['updateOne']['filter']);
97+
console.log('what is op after', op);
98+
99+
if (model.schema.$timestamps != null && op['updateOne'].timestamps !== false) {
100+
const createdAt = model.schema.$timestamps.createdAt;
101+
const updatedAt = model.schema.$timestamps.updatedAt;
102+
applyTimestampsToUpdate(now, createdAt, updatedAt, op['updateOne']['update'], {});
103+
}
104+
105+
if (op['updateOne'].timestamps !== false) {
106+
applyTimestampsToChildren(now, op['updateOne']['update'], model.schema);
107+
}
104108
} catch (error) {
105109
return callback(error, null);
106110
}

lib/helpers/query/castUpdate.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
9999
const op = ops[i];
100100
val = ret[op];
101101
hasDollarKey = hasDollarKey || op.startsWith('$');
102-
102+
console.log('what is val', val);
103103
if (val &&
104104
typeof val === 'object' &&
105105
!Buffer.isBuffer(val) &&
@@ -110,7 +110,6 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
110110
+ 'Expected an object, received ' + typeof val;
111111
throw new Error(msg);
112112
}
113-
114113
if (op.startsWith('$') && utils.isEmptyObject(val)) {
115114
delete ret[op];
116115
}

lib/model.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,7 +3335,6 @@ Model.bulkWrite = async function bulkWrite(ops, options) {
33353335
const ordered = options.ordered == null ? true : options.ordered;
33363336

33373337
const validations = ops.map(op => castBulkWrite(this, op, options));
3338-
33393338
return new Promise((resolve, reject) => {
33403339
if (ordered) {
33413340
each(validations, (fn, cb) => fn(cb), error => {
@@ -3352,7 +3351,6 @@ Model.bulkWrite = async function bulkWrite(ops, options) {
33523351
if (error) {
33533352
return reject(error);
33543353
}
3355-
33563354
resolve(res);
33573355
});
33583356
} catch (err) {
@@ -3424,7 +3422,6 @@ Model.bulkWrite = async function bulkWrite(ops, options) {
34243422
res.mongoose.results = results;
34253423
}
34263424
}
3427-
34283425
resolve(res);
34293426
});
34303427
}

test/model.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6417,7 +6417,7 @@ describe('Model', function() {
64176417
update: { $set: timeDoc }
64186418
}
64196419
}]);
6420-
assert.deepStrictEqual(beforeSet, timeDoc)
6420+
assert.deepStrictEqual(beforeSet._doc, timeDoc)
64216421

64226422
const timelessDoc = await Timeless.create({
64236423
name: 'Timeless Test'

0 commit comments

Comments
 (0)