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

Docs error: wrong parameter order for distinct() #2628

Closed
ItalyPaleAle opened this issue Jan 28, 2015 · 6 comments
Closed

Docs error: wrong parameter order for distinct() #2628

ItalyPaleAle opened this issue Jan 28, 2015 · 6 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@ItalyPaleAle
Copy link

The docs ( http://mongoosejs.com/docs/api.html#query_Query-distinct ) say that the parameter order is: Query#distinct([criteria], [field], [callback]).

After wasting 30 minutes with a very obscure error when using all 3 arguments, I found out that the parameter are actually reversed: Query#distinct([field], [criteria], [callback]). This works.

vkarpov15 added a commit that referenced this issue Jan 29, 2015
@vkarpov15 vkarpov15 added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Jan 29, 2015
@vkarpov15
Copy link
Collaborator

Well that's embarrassing. Fixed. Thanks for pointing that out.

@vkarpov15 vkarpov15 added this to the 3.8.23 milestone Jan 29, 2015
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed docs This issue is due to a mistake or omission in the mongoosejs.com documentation labels Jan 29, 2015
@vkarpov15 vkarpov15 modified the milestones: 4.0.0-rc0, 3.8.23 Jan 29, 2015
vkarpov15 added a commit that referenced this issue Jan 29, 2015
This reverts commit b7c854a.
@vkarpov15
Copy link
Collaborator

Actually, the docs are correct: distinct() queries take field and criteria in reverse order. So:

Model.distinct(field, criteria, callback)

But

Model.find().distinct(criteria, field, callback);

I never noticed this, its a really bad design decision that predates my involvement in mongoose. Going to fix this now. Unfortunately, its backwards breaking, so it won't go in to 3.8.x.

@vkarpov15 vkarpov15 reopened this Jan 29, 2015
@ItalyPaleAle
Copy link
Author

MongoDB's APIs use (field, criteria) ( http://docs.mongodb.org/manual/reference/method/db.collection.distinct/ ). I think this order would be the most consistant?

Anyways, I'm not sure I understood exactly: what's the final call? What changes now and what will change on 3.0?

Thanks for taking care of this

@vkarpov15
Copy link
Collaborator

Mongoose will be consistent with the MongoDB API in 4.0: it will be distinct(field, criteria, callback)

@ItalyPaleAle
Copy link
Author

And for now it will be like this?

Model.distinct(field, criteria, callback)
Model.find().distinct(criteria, field, callback)

So the only change in 4.0 is with the Model.find().distinct()? That works for me. Thanks!

@vkarpov15
Copy link
Collaborator

Yeah exactly. Both cases will be field, criteria

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants