[DRIVERS-948] Support singleBatch option in newer drivers Created: 23/Jan/20 Updated: 31/Mar/20 Resolved: 31/Mar/20 |
|
| Status: | Closed |
| Project: | Drivers |
| Component/s: | CRUD |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Patrick Freed | Assignee: | Unassigned |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
The crud spec currently omits the singleBatch option from FindOptions in favor of the legacy negative limit behavior used with pre 3.2 servers. See the second to last question in the Q&A section for more info and justification. Newer drivers (e.g. Swift and Rust) never supported this legacy behavior in the first place, so it may make sense for them to just support the singleBatch option directly and only accept unsigned limits instead. It would lead to a minor API difference between newer drivers and the old ones, but that difference would exist in the name of simplicity and clarity, so I'm not sure how much of a concern it is. |
| Comments |
| Comment by Jeffrey Yemin [ 30/Mar/20 ] |
|
limit should be non-negative. |
| Comment by Patrick Freed [ 24/Jan/20 ] |
Good point, noted.
And for limit on regular find, just support non-negative values? |
| Comment by Jeremy Mikola [ 24/Jan/20 ] |
FWIW, batchSize would be redundant in this case and you also shouldn't need singleBatch. A limit of one should be sufficient to instruct the server to select one document and immediately close the cursor. |
| Comment by Bernie Hackett [ 24/Jan/20 ] |
|
Feel free to use it internally for findOne, just don't expose the singleBatch option in the public API. |
| Comment by Patrick Freed [ 24/Jan/20 ] |
|
I was primarily interested in it for implementing a findOne helper, but that can be achieved with just limit: 1 and batchSize: 1. That said, if a user doesn't know how many documents are in a collection but they do know that they want to minimize round trips to the server, singleBatch: true could be useful. I'm not sure how common that case is, though. |
| Comment by Bernie Hackett [ 24/Jan/20 ] |
|
Before we do such a thing I think we need to understand use cases for single batch. IIRC, we added single batch so drivers could continue to offer negative limit support (i.e. we were avoiding a backward breaking change), but I don't recall ever hearing why negative limit support was important. |