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

Not validating findOne arguments properly

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

      Add next test code to Node.js mongodb driver test suite.

      exports['Should correctly find one document with custom fields and undefined callback'] = {
        metadata: {
          requires: {
            promises: true,
            topology: ['single']
          }
        },
        test: function (configuration, test) {
          var db = configuration.newDbInstance(configuration.writeConcernMax(), {
            poolSize: 1,
            auto_reconnect: false
          });
      
          db.open().then(function (db) {
            var collection = db.collection('findOneDocumentCustomFieldsUndefinedCallback');
            collection.insertMany([{
              a: 1,
              b: 1
            }, {
              a: 2,
              b: 2
            }, {
              a: 3,
              b: 3
            }, {
              a: 4,
              b: 4
            }], configuration.writeConcernMax()).then(function (result) {
      
              // Show that duplicate records got dropped
              collection.findOne({
                a: 1
              }, {
                fields: {
                  b: 1,
                  _id: 0
                }
              }, undefined).then(function (item) {
                test.equal(item._id, undefined);
                test.equal(item.b, 1);
                test.equal(item.a, undefined);
                db.close();
                test.done();
              });
            });
          });
        }
      }
      

      I expect findOne works in the same way with two arguments and three arguments with undefined or null as value.

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            toni-loriot Antonio
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: