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

BSON lib throwing error when serializing

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.0
    • Affects Version/s: None
    • Component/s: js-bson
    • None

      Steps to repro:

      1. Using mongodb 3.6 rc1, node v8.8.1, npm 5.4.2
      2. Get a replicate set created
      3. Using the following package.json

      {
        "dependencies": {
          "mongodb": "mongodb/node-mongodb-native#3.0.0"
        }
      }
      

      4. And the following index.js file

      const { MongoClient } = require('mongodb');
      
      const uri = 'mongodb://localhost:27017/chat';
      
      const pipeline = [
        { $match: { operationType: { $in: ['insert', 'replace'] } } },
      ];
      
      async function connect() {
        const client = await MongoClient.connect(uri);
        const db = client.db('chat');
        const collection = db.collection('messages');
      
        const changeStream = collection.watch(pipeline);
        changeStream.on('change', change => {
          console.log('Change', change);
        });
      
        await collection.insert({ id: 1, name: 'harry', time: new Date() });
      
        setTimeout(() => {
          process.exit(0);
        }, 1000);
      }
      
      connect().catch(err => console.dir(err, { depth: 5 }));
      

      5. Executing `node index.js` results in the following stack trace:

      ➜  ~/Sites/weather-chat git:(master) ✗ node index.js
      Error: key $clusterTime must not start with '$'
          at serializeInto (/Users/hswolff/Sites/weather-chat/node_modules/bson/lib/bson/parser/serializer.js:751:19)
          at BSON.serialize (/Users/hswolff/Sites/weather-chat/node_modules/bson/lib/bson/bson.js:58:27)
          at Query.toBin (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/node_modules/mongodb-core/lib/connection/commands.js:141:25)
          at serializeCommands (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:1016:43)
          at Pool.write (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:1185:3)
          at executeWrite (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:75:10)
          at WireProtocol.insert (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:86:3)
          at Server.insert (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:737:35)
          at Server.insert (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/lib/topologies/topology_base.js:322:25)
          at executeBatch (/Users/hswolff/Sites/weather-chat/node_modules/mongodb/lib/bulk/unordered.js:478:23)
      

      Should these modules be using the 2.0 branch of BSON instead of the 1.0 branch?

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            harry.wolff@mongodb.com Harry Wolff
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: