howdyai / botkit-storage-mongo

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

Can get method return a promise? #16

Closed maxhartshorn closed 7 years ago

maxhartshorn commented 8 years ago

Running the following example given in README.md, controller.storage.teams.get('cool') returns null

var beans = {id: 'cool', beans: ['pinto', 'garbanzo']}; controller.storage.teams.save(beans); beans = controller.storage.teams.get('cool');

It looks like the underlying Monk api returns a promise, but that promise is not returned by the get function so we get beans === null.

How would people feel about changing table.findOne({id: id}, cb); to return table.findOne({id: id}, cb); in the get function and table.find({}, cb); to return table.find({}, cb); in the all function? This way plugin users can handle the promise themselves.

I can submit a pull request for this.

I realize there is a callback option...why not support both promises and callbacks?

benbrown commented 7 years ago

I just added support for promises. Thanks for pointing out that this was already built in to Monk, @maxhartshorn!