Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-3009

Ensure findOne does not set batchSize=1

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Component/s: CRUD
    • Needed
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      CDRIVER-5771 Blocked
      CXX-3137 Blocked
      CSHARP-5376 Blocked
      GODRIVER-3395 Blocked
      JAVA-5666 Blocked
      NODE-6471 Blocked
      MOTOR-1387 Duplicate
      PYTHON-4920 Blocked
      PHPLIB-1563 Blocked
      RUBY-3567 Blocked
      RUST-2070 Blocked
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion CDRIVER-5771 Blocked CXX-3137 Blocked CSHARP-5376 Blocked GODRIVER-3395 Blocked JAVA-5666 Blocked NODE-6471 Blocked MOTOR-1387 Duplicate PYTHON-4920 Blocked PHPLIB-1563 Blocked RUBY-3567 Blocked RUST-2070 Blocked

      Most (all?) drivers have a collection.findOne() helper but the CRUD spec only says this:

      Q: Speaking of "One", where is findOne?

      If your driver wishes to offer a findOne method, that is perfectly fine. If you choose to implement findOne, please keep to the naming conventions followed by the FindOptions and keep in mind that certain things don't make sense like limit (which should be -1), tailable, awaitData, etc...

      https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#q--a

      We should add tests to ensure that drivers MUST NOT send batchSize=1 with the findOne operation as doing so is unneeded and, at worst, requires the driver to run killCursors. This extra killCursors command is inefficient and adds latency to the findOne(). See SERVER-80713 and SERVER-57067 for more info.

      Why am I opening this now?

      While looking into HELP-66136 I saw that Node's findOne api is sending both limit=1 and batchSize=1:

        async findOne(
          filter: Filter<TSchema> = {},
          options: FindOptions = {}
        ): Promise<WithId<TSchema> | null> {
          const cursor = this.find(filter, options).limit(-1).batchSize(1);
          const res = await cursor.next();
          await cursor.close();
          return res;
        }
      

      https://github.com/mongodb/node-mongodb-native/blob/c54466c/src/collection.ts#L506

      Note that to reproduce this you may need to set internalQueryFrameworkControl="trySbeEngine":

      >>> client.admin.command('buildInfo')['version']
      '7.0.8'
      >>> client.t.command("find", "t", batchSize=1, limit=1)
      {'cursor': {'firstBatch': [{'_id': ObjectId('670ff88ad508463d0358f622')}], 'id': 0, 'ns': 't.t'}, 'ok': 1.0, ...}
      >>> client.admin.command({'setParameter': 1, 'internalQueryFrameworkControl': 'trySbeEngine'})
      {'was': 'trySbeRestricted', 'ok': 1.0, ...}
      >>> client.t.command("find", "t", batchSize=1, limit=1)
      {'cursor': {'firstBatch': [{'_id': ObjectId('670ff88ad508463d0358f622')}], 'id': 5525733552195222418, 'ns': 't.t'}, 'ok': 1.0, ...}
      

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Andreas Braun Andreas Braun
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: