Skip to content

Parse.Query.toJSON() not working for aggregate query #918

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

Open
mtrezza opened this issue Sep 9, 2019 · 15 comments
Open

Parse.Query.toJSON() not working for aggregate query #918

mtrezza opened this issue Sep 9, 2019 · 15 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@mtrezza
Copy link
Member

mtrezza commented Sep 9, 2019

Issue Description

Parse.Query.toJSON() returns an empty query when the query is an aggregate query.

Steps to reproduce

const query = new Parse.Query("MyCollection");
const pipeline = {
    "match":{"language":{"$in":[null,"en"]}},
};
const results = await query.aggregate(pipeline);
const queryJson = query.toJSON(); // returns `{where: {}}`

Expected Results

query.toJSON() should return the aggregate query.

Actual Outcome

query.toJSON() returns {where: {}}.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 3.8.0
    • Operating System: -
    • Hardware: -
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): -
  • JS SDK

    • JS SDK version: 2.7.0
    • Application? (Browser, Node, React-Native, etc): -

Logs/Trace

@dplewis
Copy link
Member

dplewis commented Sep 10, 2019

You want to implement query.setPipeline()?

@mtrezza
Copy link
Member Author

mtrezza commented Sep 10, 2019

Actually I will close this for now if that's OK, there may be more important issues/feature requests coming up. At least we have it documented here.

@mtrezza mtrezza closed this as completed Sep 10, 2019
@RaschidJFR
Copy link
Contributor

@mtrezza what's your use case for this feature?

@mtrezza
Copy link
Member Author

mtrezza commented May 23, 2020

@RaschidJFR why are you asking?

Sent with GitHawk

@dplewis
Copy link
Member

dplewis commented May 23, 2020

I forgot about this feature, I can do a PR if you want

@mtrezza
Copy link
Member Author

mtrezza commented May 23, 2020

No-one has voiced any need for it to my knowledge, and I personally don’t need it anymore, but it would certainly be a nice-to-have feature.

Sent with GitHawk

@RaschidJFR
Copy link
Contributor

@RaschidJFR why are you asking?

Sent with GitHawk

Because I've just started working on #1170 and I thought it might be related.

@mtrezza
Copy link
Member Author

mtrezza commented May 23, 2020

@RaschidJFR Related in what sense?

This issue is about the pipeline not being serialized with toJSON().
Your PR seems to be about mixing the equalTo condition into the pipeline.

Can you please open an issue for your PR where you describe your intention, so the community can debate it if necessary? I already see some potential issues with that PR.

@RaschidJFR
Copy link
Contributor

Related in what sense?

@mtrezza I was just gathering information about similar problems to mine to try to solve them at once. Your issue is caused because aggregate() is executes the query but does not modify it, same as find() (they are sibling functions). So if you don't have a use for it anymore I'll just ignore it in my proposal.

I've created #1171 so let's move the conversation there. Please list the potential issues you've found.

@RaschidJFR
Copy link
Contributor

I forgot about this feature, I can do a PR if you want
@dplewis Please have a look at my PR #1170 and let me know if you need me to include anything else in case it goes ahead.

@zanderisrael
Copy link
Contributor

I'd love to have this feature. I there something I can do to help this move along?

@mtrezza
Copy link
Member Author

mtrezza commented Mar 23, 2022

Thanks for asking @zanderisrael, you could open a PR. To my knowledge no-one has worked on it so far. It seems fairly straight forward, because a lot of the logic to produce the JSON output for non-aggregate queries already exists.

@mtrezza mtrezza reopened this Mar 23, 2022
@mtrezza mtrezza added the type:feature New feature or improvement of existing feature label Mar 23, 2022
@zanderisrael
Copy link
Contributor

Ok then, i'll have a look.

@zanderisrael
Copy link
Contributor

Looks like I don't need this in the end. Someone else can pick this up...

@mtrezza mtrezza added type:bug Impaired feature or lacking behavior that is likely assumed and removed type:feature New feature or improvement of existing feature labels Feb 22, 2025
@dplewis
Copy link
Member

dplewis commented Apr 2, 2025

For this to work we would have to add query.pipeline

const query = new Parse.Query("MyCollection");
const pipeline = {
    "match":{"language":{"$in":[null,"en"]}},
};
const results = await query.aggregate(pipeline);

Becomes

const query = new Parse.Query("MyCollection");
query.pipeline({
    "match":{"language":{"$in":[null,"en"]}},
});
const results = await query.aggregate();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants