Open LinusU opened 3 years ago
I've tracked down the problem to somewhere inside the modifyjs
dependency:
console.error('original', original)
console.error('updates', updates)
var updated = modifyjs(original, updates);
console.error('updated', updated)
original { name: 'Test', _id: ObjectID(603cbd6635df4f1f51b83992) }
updates {
'$set': {
currentState: { price: 4900, _id: ObjectID(603cbd6635df4f1f51b83993) }
}
}
updated {
name: 'Test',
_id: ObjectID(undefined),
currentState: { price: 4900, _id: ObjectID(undefined) }
}
Okay, the problem is that bson-objectid
ObjectId
loses their internal data when they are clone
d. This doesn't seem to be a problem with ObjectId
from the official bson
package.
The following code:
Results in this printout:
Note that
currentState._id
isObjectID(undefined)