-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: 3.6.0
-
Component/s: None
v3.6.0 added a `hasAtomicOperators` check to `bulkWrite()` which doesn't take into account custom BSON transformations. For example, the below script succeeds in v3.5.8, but fails in v3.6.0:
const { MongoClient, ObjectId } = require('mongodb'); void async function() { const client = await MongoClient.connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true }); const db = client.db(); const replacement = { $internalProperty: 42, toBSON: () => ({ answer: 42 }) }; await db.collection('Test').bulkWrite([{ replaceOne: { filter: { name: 'bar' }, replacement } }]); console.log('Done'); process.exit(0); }();
We can work around this change in Mongoose, but I just wanted to make sure you're aware of this potential issue.