[CSHARP-1272] FindFluent.SizeAsync() Created: 08/May/15  Updated: 08/May/15  Resolved: 08/May/15

Status: Closed
Project: C# Driver
Component/s: Feature Request
Affects Version/s: 2.0
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Aristarkh Zagorodnikov Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I wonder if there are any plans to include a SizeAsync (
http://docs.mongodb.org/manual/reference/method/cursor.size/#cursor.size)?
I'm not sure of the wire protocol, but it seems that it might be useful at least to imitate "exists" queries (Limit(-1).SizeAsync() instead of CountAsync() when you are only interested if there is at least one document).



 Comments   
Comment by Aristarkh Zagorodnikov [ 08/May/15 ]

I checked the FindFluent.CountAsync source and it takes into account the skip/limit. Thank you again, looks like I should forget some more 1.x stuff =)

Comment by Aristarkh Zagorodnikov [ 08/May/15 ]

Thanks for pointing me to the IMongoCollection.CountAsync. And as for Skip->Limit->Count, I was under impression that it would ignore the skip and limit as 1.x driver did, if it's not the case, than that's great!

Comment by Craig Wilson [ 08/May/15 ]

Hi Aristarkh,

You can pass a CountOptions to CountAsync which can contain both a skip and a limit. http://api.mongodb.org/csharp/2.0/html/M_MongoDB_Driver_IMongoCollection_1_CountAsync.htm

In addition, you can use Find and terminate it with a count: Find(x => x.Age > 21).Skip(1).Limit(10).CountAsync()

Craig

Generated at Wed Feb 07 21:39:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.