Skip to content

Can not combine equalTo clause with any other clause #1372

Open
@sadakchap

Description

@sadakchap

New Issue Checklist

  • I am not disclosing a vulnerability.
    I am not just asking a question.
    I have searched through existing issues.
    I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK.

Issue Description

Combining equalTo clause with any other clause seem to overwriting each other.

Steps to reproduce

let q = new Parse.Query('MyClass');
q.equalTo('age', null);
q.exists('age');
// or these
q.equalTo('age', 10);
q.greaterThan('age', 0);

Actual Outcome

getting a query like this where={age: {$exists: true}} or error in 2nd case(using greaterThan)

Expected Outcome

where={age: {$exists: true, $eq: null }} or where={age: {$gt: 0, $eq: 10 }}

Environment

Server

  • Parse Server version: 4.5.0
  • Operating system: Ubuntu
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 4.4
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Client

  • Parse JS SDK version: 3.2.0

Logs

Activity

sadakchap

sadakchap commented on Jun 8, 2021

@sadakchap
MemberAuthor

Here's pr #1373 with a failing test case.

sadakchap

sadakchap commented on Jun 9, 2021

@sadakchap
MemberAuthor

After looking into code for equalTo, wherever we had queries like this

q.greaterThan(age, 0);
q.equalTo(age, 10); // this will override any existing query on that key
// will result in where={age: 10}

It seems like equalTo was always overriding any existing query on that key instead of adding new clause.

And when we try to apply other clauses to equalTo query,

q.equalTo(age, 10);
q.greaterThan(age, 0);

it was failing at line as equalTo gives where={age: 10} and won't be able to add any other clause.

Do guys think that it should return where={age: {$eq: 10, $gt: 0}} ? @davimacedo @mtrezza .

yes, we can directly use greaterThanOrEqual, but for other clauses, should equalTo override ?

dplewis

dplewis commented on Jun 9, 2021

@dplewis
Member

I posted this in the PHP SDK because a developer had the same idea you had or similar at almost the same time.

parse-community/parse-php-sdk#476

I think they came up with a good solution of using this.addCondition(key, $eq, value) vs this.where[key] just wanted you to know. I’ll look into it more

sadakchap

sadakchap commented on Jun 9, 2021

@sadakchap
MemberAuthor

Yes, that's a very good solution!
But what do you think about this scenario

q.equalTo(age, 10);
q.equalTo(age);

this will result in where={age: {$eq: 10, $exists: false}}. Do you think this make sense ?

The way queries are executed, it make sense to me. But, earlier equalTo without any compareTo value was overriding anything and giving where={age: {$exists: false}}.

test case

added
type:featureNew feature or improvement of existing feature
and removed on Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bounty:$5Bounty applies for fixing this issue (Parse Bounty Program)type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mtrezza@dplewis@sadakchap

        Issue actions

          Can not combine equalTo clause with any other clause · Issue #1372 · parse-community/Parse-SDK-JS