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

Get one document with sorting #172

Closed
MCubs opened this issue Nov 23, 2018 · 1 comment
Closed

Get one document with sorting #172

MCubs opened this issue Nov 23, 2018 · 1 comment

Comments

@MCubs
Copy link

MCubs commented Nov 23, 2018

Hello,

How I get one document with use Cursor method ->sort().
Method ->one() don`t using ->sort(), and methot ->current() deprecated.

@sokil
Copy link
Owner

sokil commented Nov 25, 2018

Method Cursor::one() is frapper for findOne, see https://docs.mongodb.com/manual/reference/method/db.collection.findOne/. Due to the manual:

If multiple documents satisfy the query, this method returns the first document according to the natural order which reflects the order of documents on the disk.

So if you need first document from sorted set, use something like ->sort([])->limit(1)->all()->current()

@MCubs MCubs closed this as completed Nov 26, 2018
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