reactivemongo.api.Cursor#collect maxDocs not respected

37 views
Skip to first unread message

João Ferreira

unread,
Oct 6, 2017, 5:05:27 AM10/6/17
to ReactiveMongo - http://reactivemongo.org
Hi

After upgrading from reactivemongo 0.11.14 to 0.12.5 I noticed that the parameter maxDocs in reactivemongo.api.Cursor#collect method is not respected, because more documents that the requested can be returned.

I have simple reproduction test case in this branch https://github.com/jtjeferreira/ReactiveMongo/tree/maxDocs-0.12, where I increased the size of the inserted documents, modified the test "get 10 first docs", and commented the other tests so it is easier to reproduce.

"get 10000 first docs" in { implicit ee: EE =>
  c
.find(matchAll("cursorspec1")).cursor().collect[List](10000).
    map
(_.size) aka "result size" must beEqualTo(10000).await(1, timeout)
}

fails with 

[error] x get 10000 first docs
[error]  '12637' is not equal to '10000' (Cursor1Spec.scala:122)

and these are the requests made to the DB

2017-10-04T19:25:24.996+0000 I COMMAND  [conn1196] query specs2-test-reactivemongo.cursorspec1066531655 query: { $query: { cursorspec1: { $exists: false } }, $readPreference: { mode: "primary" } } planSummary: COLLSCAN cursorid:598621171031 ntoreturn:10000 ntoskip:0 keysExamined:0 docsExamined:6320 numYields:49 nreturned:6319 reslen:16775855 locks:{ Global: { acquireCount: { r: 100 } }, Database: { acquireCount: { r: 50 } }, Collection: { acquireCount: { r: 50 } } } 9ms
2017-10-04T19:25:25.557+0000 I COMMAND  [conn1196] getmore specs2-test-reactivemongo.cursorspec1066531655 query: { cursorspec1: { $exists: false } } planSummary: COLLSCAN cursorid:598621171031 ntoreturn:10000 keysExamined:0 docsExamined:6318 numYields:49 nreturned:6318 reslen:16776947 locks:{ Global: { acquireCount: { r: 100 } }, Database: { acquireCount: { r: 50 } }, Collection: { acquireCount: { r: 50 } } } 5ms

I have another branch with the same test case against the 0.11.x branch in https://github.com/jtjeferreira/ReactiveMongo/tree/maxDocs-0.11 where the test passes successfully, and the requests made against the DB are

017-10-04T19:43:10.839+0000 I COMMAND  [conn25] query specs2-test-reactivemongo.cursorspec690285554 query: { $query: { cursorspec1: { $exists: false } }, $readPreference: { mode: "primary" } } planSummary: COLLSCAN cursorid:24609772243 ntoreturn:10000 ntoskip:0 keysExamined:0 docsExamined:6320 numYields:49 nreturned:6319 reslen:16775855 locks:{ Global: { acquireCount: { r: 100 } }, Database: { acquireCount: { r: 50 } }, Collection: { acquireCount: { r: 50 } } } 17ms
2017-10-04T19:43:11.328+0000 I COMMAND  [conn25] getmore specs2-test-reactivemongo.cursorspec690285554 query: { cursorspec1: { $exists: false } } planSummary: COLLSCAN cursorid:24609772243 ntoreturn:3681 keysExamined:0 docsExamined:3680 numYields:28 nreturned:3681 reslen:9773075 locks:{ Global: { acquireCount: { r: 58 } }, Database: { acquireCount: { r: 29 } }, Collection: { acquireCount: { r: 29 } } } 3ms

The difference between the two seems the ntoreturn value in the 2nd request (10000 vs 3681) 

I will now try to fix the issue, but if you have any starting pointers it would be helpful

Thanks again for this great project
Cheers
João

João Ferreira

unread,
Oct 6, 2017, 6:51:51 AM10/6/17
to ReactiveMongo - http://reactivemongo.org

Cédric Chantepie

unread,
Oct 6, 2017, 9:10:11 AM10/6/17
to ReactiveMongo - http://reactivemongo.org
Will have a look
Reply all
Reply to author
Forward
0 new messages