Promises?

81 views
Skip to first unread message

Tom Robinson

unread,
Jun 26, 2013, 9:14:38 PM6/26/13
to mongoo...@googlegroups.com
I've noticed that certain methods return promises (Query's exec, Model's list), which is great, but others (Model's find, save, count) do not.

It would be really awesome if they did. Is this something that would be merged into the core, or should it be a plugin? Is anyone working on it?

Jason Crawford

unread,
Jun 26, 2013, 9:38:59 PM6/26/13
to mongoo...@googlegroups.com
I noticed that too. Separately, I discovered that Mongoose promises are not playing nicely with chai-as-promised right now (due to a bug in chai-as-promised: https://github.com/domenic/chai-as-promised/issues/30)

Because of this, I've started augmenting Mongoose in my own app with some methods that return Q promises. Here's a gist:


Would be happy to contribute some of this to core if the maintainers like it, or to create a separate package if they don't but others find it useful.

BTW, there is also Mongoose-Q: https://github.com/iolo/mongoose-q. I didn't discover that until after I did some of my own workarounds, though, and haven't tried it.

-Jason

--
Blog: http://blog.jasoncrawford.org  |  Twitter: @jasoncrawford


On Wed, Jun 26, 2013 at 6:14 PM, Tom Robinson <tlrob...@gmail.com> wrote:
I've noticed that certain methods return promises (Query's exec, Model's list), which is great, but others (Model's find, save, count) do not.

It would be really awesome if they did. Is this something that would be merged into the core, or should it be a plugin? Is anyone working on it?

--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Aaron Heckmann

unread,
Jun 28, 2013, 11:12:35 AM6/28/13
to mongoo...@googlegroups.com
On Wed, Jun 26, 2013 at 6:14 PM, Tom Robinson <tlrob...@gmail.com> wrote:
but others (Model's find, save, count) do not.

`count` and `find` are entry points for the query builder. If you need a promise, `exec()` the query.

`save` doesn't return a promise b/c of how pre/post hooks were implemented. Someday we'll change that. https://github.com/LearnBoost/mongoose/issues/1431
Reply all
Reply to author
Forward
0 new messages