Skip to content

Added Datastore.findOpts(query, opts, callback)#489

Open
iyobo wants to merge 5 commits intolouischatriot:masterfrom
iyobo:master
Open

Added Datastore.findOpts(query, opts, callback)#489
iyobo wants to merge 5 commits intolouischatriot:masterfrom
iyobo:master

Conversation

@iyobo
Copy link
Copy Markdown

@iyobo iyobo commented Jan 15, 2017

findOpts is an extended version of the find function, where the 2nd parameter (previously just projections) is now used to pass in fields (aka projections), paging, and sort values which, for the most part, eliminates the need to return a cursor.

This function will never return a cursor and will always expect the last parameter to be a callback, keeping it auto-promisification compliant.

i.e. With this function, you can now run promise.promisifyAll(...) on an instance of Datastore to be able to use await or yield on findOptsAsync with all working find features whereas simply using findAsync function would be severely handicapped as it would not be able to page or sort.

@PopovMP
Copy link
Copy Markdown

PopovMP commented Jan 15, 2017

Yes, this make sense. However, I would recommend adding additional options to the standard find, findOne and count projection as: $skip, $limit, and $sort instead of adding new command.
Example:
db.find({}, {username: 1, email: 1, _id: 0, $skip: 20, $limit: 10, $sort: {username: 1} }, callback)

@iyobo
Copy link
Copy Markdown
Author

iyobo commented Jan 15, 2017

The main issue with that is neither count nor findOne are paged or sorted.
Secondarily, it's rather messy.

The criteria should remain seperate from query options.

@PopovMP
Copy link
Copy Markdown

PopovMP commented Jan 16, 2017

You may be right. However, I don't think we should add this pull request to the official distribution.
You may make a wrapper for NeDB with that functionality that will work over the original package.

I hope @louischatriot will take a clever decision.

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

Successfully merging this pull request may close these issues.

2 participants