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

promoteValues in find seems not to apply for subsequent getmores

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.26
    • Affects Version/s: 2.2.25
    • Component/s: None
    • None

      I have a find() command that uses the {promoteValues: false} option to get access to the BSON types directly. This seems to work correctly for the first 101 documents (first batch), but subsequent documents seem to be promoted to javascript values again.

      Is it possible the promoteValues option is not passed to subsequent getmores in this case?

      Here is a test script that inserts some BSON values and then asserts they are returned as BSON. It passes for up to 101 documents, but fails for limits higher than that.

      var mc = require('mongodb').MongoClient;
      var bson = require('bson');
      var assert = require('assert');
      
      mc.connect('mongodb://localhost:27017/test', function(err, db) {
        if (err) throw err;
        var docs = new Array(150).fill(0).map(function(_, i) {
          return {
            _id: 'needle_' + i,
            is_even: i % 2,
            long: bson.Long.fromString('1234567890'),
            double: 0.23456,
            int: 1234
          };
        });
        db.collection('haystack').insert(docs, function(errInsert) {
          if (errInsert) throw errInsert;
          // change limit from 102 to 101 and this test passes.
          // seems to indicate that the promoteValues flag is used for the
          // initial find, but not for subsequent getMores
          db.collection('haystack').find({}, {limit: 102, promoteValues: false})
            .on('data', function(doc) {
              assert.equal(typeof doc.int, 'object');
              assert.equal(doc.int._bsontype, 'Int32');
              assert.equal(typeof doc.long, 'object');
              assert.equal(doc.long._bsontype, 'Long');
              assert.equal(typeof doc.double, 'object');
              assert.equal(doc.double._bsontype, 'Double');
            })
            .on('end', function() {
              db.dropCollection('haystack', function() {
                db.close();
              });
            });
        });
      });
      

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: