[SERVER-56905] Ban API params to aggregate/find/etc shell helpers Created: 12/May/21  Updated: 29/Oct/23  Resolved: 13/Oct/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.2.0

Type: New Feature Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Nicholas Zolnierz
Resolution: Fixed Votes: 0
Labels: greenerbuild, quick-tech-debt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Participants:

 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.



 Comments   
Comment by Githook User [ 12/Oct/21 ]

Author:

{'name': 'Nicholas Zolnierz', 'email': 'nicholas.zolnierz@mongodb.com', 'username': 'nzolnierzmdb'}

Message: SERVER-56905 Ban API params to aggregate/find/etc shell helpers
Branch: master
https://github.com/mongodb/mongo/commit/a8bb7e666abb24d8caa27b33d484e8d1e871c458

Generated at Thu Feb 08 05:40:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.