[GODRIVER-1605] Allow cursor options to be specified when using RunCommandCursor Created: 05/May/20  Updated: 28/Oct/23  Resolved: 23/Mar/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.12.0, 1.11.7

Type: Improvement Priority: Major - P3
Reporter: Divjot Arora (Inactive) Assignee: Preston Vasquez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to DRIVERS-1589 Allow changing BatchSize for getMores... Backlog
is related to GODRIVER-1900 Add SetBatchSize method to driver.Bat... Closed
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The Database.RunCommandCursor method doesn't allow users to specify cursor options that are part of getMore rather than the initial find/aggregate/etc. We should figure out how we can add this functionality without changing the API. One thought is to add them to options.RunCmdOptions and document that they only apply to RunCommandCursor.



 Comments   
Comment by Githook User [ 05/Jun/23 ]

Author:

{'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}

Message: GODRIVER-1605 Add SetBatchSize to mongo.Cursor (#1201)

Co-authored-by: Matt Dale <9760375+matthewdale@users.noreply.github.com>
Branch: release/1.11
https://github.com/mongodb/mongo-go-driver/commit/67f33810ad9ce35bf9dca29691503baf3ce6a4ef

Comment by Githook User [ 23/Mar/23 ]

Author:

{'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}

Message: GODRIVER-1605 Add SetBatchSize to mongo.Cursor (#1201)

Co-authored-by: Matt Dale <9760375+matthewdale@users.noreply.github.com>
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/8d7f05ff302ffbdd0d82836d51bbd6d53dfe908d

Comment by Huan Li [ 13/Feb/23 ]

esha.bhargava@mongodb.com We are not literally "blocked" by this feature. But a few of our recent replication failures were caused by the cursor timeout. With this new feature, we could largely avoid such failures.

Comment by Matt Dale [ 13/Feb/23 ]

Some additional implement options:

Get batch size from RunCommandCursor command

Another way to implement this is to fetch the "batchSize" from the command document and use that as the "batchSize" option when we create the cursor. There are pros and cons to that approach:

Pros:

  • No API syntax changes required.
  • Batch size only needs to be specified in a single place.

Cons:

  • Different commands specify batch size in different places in the command document, so we'd have to write logic to fetch "batchSize" for each command that creates a cursor.
  • May be less obvious to users who expect to set batch size on an options struct. It's on us to document it well.

Add Cursor.SetBatchSize

A 3rd option is to add a function SetBatchSize to Cursor that allows setting batch size on a Cursor after creating it. Inspired by the Python driver API cursor.batch_size. Pros/cons:

Pros:

  • Adding SetBatchSize to Cursor is extremely simple to implement and has no impact on
  • Providing a way to set batch size on a Cursor technically provides a way for users to fetch an empty batch, then change the batch size for subsequent "getMore" commands. See PYTHON-2563 for inspiration.

Cons:

  • For the vast majority of users, SetBatchSize would be redundant because they only want to set the batch size once on the original command. It could add confusion for users who don't understand why it's there.

Compare to pros/cons of adding a BatchSize option to options.RunCmdOptions as suggested in the ticket description:

Pros:

  • Specifying a cursor batch size is obvious.

Cons:

  • Applying the BatchSize option to the original command could be difficult because different command documents specify batch size in different places. If we only apply the batch size to the cursor (not the original command), then users have to specify batch size twice (if they care about the size of the initial batch).
  • RunCmdOptions would have values that don't apply to RunCommand, which could be confusing. That's something we'd want to fix in Go Driver 2.0 by separating options for RunCommand and RunCommandCursor.
Comment by Huan Li [ 09/Feb/23 ]

kevin.eric.albertson@gmail.com matt.dale@mongodb.com Can we reprioritize this ticket based on the discussion here?

Generated at Thu Feb 08 08:36:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.