Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't limit amount of returned rows *MongoDB #497

Closed
nazriel opened this issue Feb 5, 2014 · 3 comments
Closed

Can't limit amount of returned rows *MongoDB #497

nazriel opened this issue Feb 5, 2014 · 3 comments

Comments

@nazriel
Copy link
Contributor

nazriel commented Feb 5, 2014

I would like to replicate such mongo db command:

db.users.find().sort({title: -1}).limit(3)

But I am currently stuck at:

db["users"].find().sort(Bson(["title": Bson(-1)]))

Is MongoCursor missing limit method or there is another way around this?

Thanks!

@s-ludwig
Copy link
Member

s-ludwig commented Feb 6, 2014

What you can do is to set the num_docs_per_chunk parameter of the find call to the limit (or a fraction thereof) and then use std.range.take to limit the amount of items requested:

db["users"].find(Bson.emptyObject, null, QueryFlags.none, 0, 3).sort(["title": -1]).take(3)

Unfortunately that requires setting a bunch of default parameters. A convenience function in MongoCursor should be added instead.

@nazriel
Copy link
Contributor Author

nazriel commented Feb 6, 2014

@s-ludwig #499

@nazriel
Copy link
Contributor Author

nazriel commented Feb 6, 2014

Fixed.
Thanks alot @s-ludwig !

@nazriel nazriel closed this as completed Feb 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants