howdyai / botkit-storage-mongo

A MongoDB storage driver for Botkit
MIT License
54 stars 42 forks source link

Support passing options to `.find()` #39

Open ericrallen opened 5 years ago

ericrallen commented 5 years ago

It doesn't seem to be possible to use sort or limit with botkit-storage-mongo because the exposed API does not accept options and pass them through to monk.

This means you can only ever retrieve all of the items in a collection that meet your query parameters and they will be returned in an order determined by Mongo.

This is less than ideal for many usecases.

I plan to submit a PR to address this, but am not sure whether you'd rather the exposed API become polymorphic and allow the options to be an optional second parameter, which I think the monk API supports, or if you'd prefer we break the convention of the monk API and add the options as an argument after the callback. Either of these options should be backwards compatible and not break any existing code that uses botkit-storage-mongo.

ericrallen commented 5 years ago

Here is the relevant documentation from monk: https://automattic.github.io/monk/docs/collection/find.html

ericrallen commented 5 years ago

Here's a StackOverflow answer showing it in practice: https://stackoverflow.com/a/19955252/656011

And here's the relevant code from monk. It appears they use a polymorphic signature where the options arguments is optional. I'm working on a PR now that mirrors their approach.