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

Model.create(Array) promise is spreading arguments #2582

Closed
jtmarmon opened this issue Jan 8, 2015 · 6 comments
Closed

Model.create(Array) promise is spreading arguments #2582

jtmarmon opened this issue Jan 8, 2015 · 6 comments
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@jtmarmon
Copy link

jtmarmon commented Jan 8, 2015

@vkarpov15 mentions in #2478 that if you pass an array to Model.create, the promise is resolved with an array. However, [in the docs](http://mongoosejs.com/docs/api.html#model_Model.create it looks like the arguments are spread, and my code is showing the same. Would love some clarification here if possible

@vkarpov15
Copy link
Collaborator

3.8.x always returns them as a spread, 3.9.x (and 4.0) will return them as an array if you pass an array and spread if you pass in a spread. The reasoning for this is that it's a backwards breaking change, so needs to be in the unstable branch. 4.0 is currently waiting on MongoDB server 2.8 and MongoDB node driver 2.0 to stabilize before releasing.

@vkarpov15 vkarpov15 added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Jan 9, 2015
@jtmarmon
Copy link
Author

jtmarmon commented Jan 9, 2015

got it. thanks

@Soviut
Copy link

Soviut commented Jan 17, 2015

I created an issue about this regarding the callback as well #2602

@jtmarmon
Copy link
Author

oy this came back and bit me again. For anyone who stumbles upon this, Q and Mongoose basically have opposing philosophies (until 3.9/4.0). if you convert Model.create(<array>) to a Q promise, you'll lose all results past index 0. see kriskowal/q#357

@vkarpov15
Copy link
Collaborator

Yeah Q doesn't support resolving with a spread, but mongoose's underlying library mpromise does. Technically, neither promises/A+ spec nor ES6 spec explicitly prohibits resolving with a spread, although ES6 implies only a single value. To work around this, in 3.9.x and upcoming 4.x, Model.create() will return a spread if you passed it a spread and an array if you passed it an array.

@jtmarmon
Copy link
Author

Actually what just occurred to me is that I could use Q.spread. Still confusing though. Gonna be excited to get arrays back in 4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

3 participants