[JAVA-2418] cursor.setBatchSize() seems not working Created: 22/Dec/16 Updated: 27/Oct/23 Resolved: 28/Dec/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Async |
| Affects Version/s: | 3.4.1 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Alireza Mohamadi [X] | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 10 x64 |
||
| Attachments: |
|
| Description |
|
Hi. Part of my code: |
| Comments |
| Comment by Jeffrey Yemin [ 28/Dec/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the code sample. I now see what the problem is. The batch size set on the AsyncBatchCursor doesn't apply to the first batch of documents, only to the subsequent batches. To apply to the first batch, set the batch size on the FindIterable instead, e.g.:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alireza Mohamadi [X] [ 22/Dec/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FiberAsync.execute() is Quasar's way to do async operations inside a Fiber. You may ignore this part and simply consider normal API calls. Many thanks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 22/Dec/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I also can't reproduce this on 3.2. Can you provide a full code sample that reproduces the issue? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alireza Mohamadi [X] [ 22/Dec/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Jeff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 22/Dec/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Alireza, I understand what you're trying to do now. Thanks for clarifying. I'm not able to reproduce your results with a MongoDB 3.4 standalone server. Please let us know what version of MongoDB you're running against and what configuration (standalone, replica set, sharded cluster). Thanks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alireza Mohamadi [X] [ 22/Dec/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for reply. Well If I can't get 1 result at a time, I can't be sure that results still hold query conditions or not. I mean that for example in the above code I have 4 results, user requests one, I send first element of these four, and 5 minutes later user comes back and requests for another result. I should return second result but it may have changed in DB. That's the reason why I want driver to return exactly one result from MongoDB, because just when server has already sent a document to you, you can't be sure if it is changed in DBMS side or not. But if I use cursors as they get maintained over time, and get one result each time, I can be sure that results still fit my request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 22/Dec/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The batch size controls the size of the batches returned by the server. It doesn't affect the total number of results. Perhaps what you need is limit rather than batch size? If you want a single result, you can use com.mongodb.async.client.MongoIterable#first as a short cut. |