Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56905

Ban API params to aggregate/find/etc shell helpers

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.2.0
    • Component/s: None
    • Backwards Compatibility:
      Fully Compatible

      Description

      getMore requires the same API params as the cursor-creating command (SERVER-56550), but the shell helpers for cursor-creating commands like db.collection.aggregate() don't implement this, so if you do:

      var cursor = db.collection.aggregate({}, {apiVersion: "1"}) 
      cursor.toArray()

      ... if there's more than one batch, the shell calls getMore without the API params and the server returns APIMismatchError.

      I think this behavior's appropriate. It's consistent with drivers. We don't expect users to pass API params directly into commands or helper methods when they use drivers. The expected way to use API params with drivers is by passing them to MongoClient(), and the expected way with the shell is to pass --apiVersion 1 on the command line. Those ways work correctly with getMore.

      However, this leaves a booby trap for tests: if the results for aggregate, etc, fit in the first batch, then the JS above will succeed. Once the test is deployed, something might change to cause the JS above to execute getMore and fail.

      I propose that cursor-creating shell helper methods ban API parameters. Tests can use runCommand if they know what they're doing.

        Attachments

          Activity

            People

            Assignee:
            nicholas.zolnierz Nicholas Zolnierz
            Reporter:
            jesse A. Jesse Jiryu Davis
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: