Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2741

v3.6.0 `bulkWrite()` atomic operators check doesn't apply `toBSON()` before checking

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0.0
    • Affects Version/s: 3.6.0
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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.

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            val@karpov.io Valeri Karpov
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: