Skip to content

Distinct query - limit and order? #4880

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

Closed
rihadavid opened this issue Jul 8, 2018 · 1 comment
Closed

Distinct query - limit and order? #4880

rihadavid opened this issue Jul 8, 2018 · 1 comment

Comments

@rihadavid
Copy link
Contributor

Hi, I've just discovered a distinct query and I tried to use it to get unique comment authors from a list of comments. The query restrictions work well, but it seems that it is not possible to get like "5 newest authors", because the ordering and limiting do not work.

I think this is most probably not implemented, it would be awesome if somebody could do it :)
I have no idea how complicated this could be. What do you think @dplewis ? :) 🥇
Of course, I can use just a usual query, but the distinct query seems much more efficient, I like it!

var subcommentsQuery = new Parse.Query("Comment");

//those work as expected
subcommentsQuery.equalTo("pComment", savedObject);
subcommentsQuery.notContainedIn("author", [editingUser, savedObject.get("author")]);
if (savedObject.get("forAll"))
    subcommentsQuery.greaterThan("createdAt", addHours(new Date(), -36));

//those does not work at all (when using the distinct query)
subcommentsQuery.ascending("createdAt");
subcommentsQuery.limit(1);

return subcommentsQuery.distinct("author").then( ...
@dplewis
Copy link
Member

dplewis commented Jul 10, 2018

@rihadavid As far as I can tell distinct for mongo doesn't support limit and sort options. It also returns a promise instead of a cursor. You can use the regular aggregate stages group.

http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#distinct

However the options it does support aren't implemented yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants