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

MongoError: unknown operator: $$eq #532

Closed
5 tasks done
zekylaf opened this issue Jul 1, 2019 · 13 comments · Fixed by #584
Closed
5 tasks done

MongoError: unknown operator: $$eq #532

zekylaf opened this issue Jul 1, 2019 · 13 comments · Fixed by #584
Assignees
Milestone

Comments

@zekylaf
Copy link

zekylaf commented Jul 1, 2019

Hi, I was using v3.9.2 and it was working good. Recently I updated to v5.0.0 and I am getting this error when trying to use $eq operator.

MongoError: unknown operator: $$eq

I am using allowExtendedOperators: true.

The way I am using it:

var args = {
  where: {
    title: {
      "$eq": {
        name: "book name",
        description: "book description"
      }
    }
  }
}

Book.find(args, function(err, res){
  ...
});

Something I can do?
Thanks

Acceptance Criteria

  • Investigate and find the cause
  • add explanations and examples to the mongodb connector dosc
  • remove pushAll from the list as it is deprecated.
  • MongoDB operations have the prefix $. Even the LB4 supported operations don't need the $, Mongodb users might tend to add the prefix. This issue might be caused by removing the step to clean$ in the buildWhere. Maybe we can add it back.
  • Update tests to include the bug caught
@dhmlau
Copy link
Member

dhmlau commented Jul 1, 2019

@hacksparrow , could you please take a look? Thanks.

@hacksparrow
Copy link
Contributor

@zekylaf can you share a sample app reproducing the error? I checked on a LB3 app, I don't get that error.

@zekylaf
Copy link
Author

zekylaf commented Jul 2, 2019

Sure. https://github.com/zekylaf/lb-eq-test

Run it with:

  • npm install
  • npm run testeq

I could verify that this happens with loopback-connector-mongodb v4.0.0 or greater. It works fine with v3.9.2

Thanks

@hacksparrow
Copy link
Contributor

Thanks @zekylaf

@hacksparrow
Copy link
Contributor

@zekylaf please use this workaround while we work on a solution:

  var args = {
    where: {
      'title.name': 'book name',
      'title.description': 'book description',
    }
  };

@zekylaf
Copy link
Author

zekylaf commented Jul 8, 2019

@hacksparrow great, thanks.

@stale
Copy link

stale bot commented Sep 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 7, 2019
@stale
Copy link

stale bot commented Sep 21, 2019

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Sep 21, 2019
@fhsakai
Copy link

fhsakai commented Feb 12, 2020

Dear @hacksparrow,
That issue is closed, but is there any plan to correct it?
Should I open a new one?
To allow to use the mongoDB operator without duplicate the $

until the release v3.9.2 we have in the buildWhere a step to clean $ from the operator before the handler
if (spec.charAt(0) === '$') spec = spec.substr(1); ( v3.9.2)
but it's since v4.0.0

@hacksparrow
Copy link
Contributor

Re-opened. @fhsakai

@hacksparrow hacksparrow reopened this Feb 17, 2020
@stale stale bot removed the stale label Feb 17, 2020
@dhmlau
Copy link
Member

dhmlau commented Feb 17, 2020

@agnes512, could you please take a look at this? Thanks.

@stale
Copy link

stale bot commented Apr 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 17, 2020
@agnes512 agnes512 removed the stale label Apr 17, 2020
@agnes512
Copy link
Contributor

agnes512 commented Jun 9, 2020

For everyone who's watching is issue:

  • for MongoDB supported update operators:

    • $currentDate, $inc, $max, $min, $mul, $rename, $setOnInsert, $set, $unset
    • $addToSet, $pop, $pullAll, $pull, $push
    • $bit
      They work with "^5.0.0" as well. To enable these operators, please indicate allowExtendedOperators: true in your datasource configuration or the model definition. ( up to what scope you'd like to have)
    • e.g productRepo.updateAll({ $max: { price: 100 }})
  • for other query operators, such as eq lt and, etc:
    Please check out the Where filter docs. It lists all the operators that LB supports and example usages. $ is not needed for these operatrs.

    • e.g do {where: {name:{ eq: 'LoopBack' } instead

And here are some examples for using the MongoDB update operators:

  • Update the price for all the products if their current price is lower than 100:
    • For LB4 users:
 await productRepo.updateAll({ $max: { price: 100 }}, {// where clause goes in here});

you might need to do some type conversion to make Typescript happy:

 await productRepo.updateAll({ $max: { num: 100 } } as unknown as Product);
  • For LB3 users:
Product.updateAll(
            {// where clause goes in here},
            {$max: {price: 100}},
            options,
            function(err, updateproducts) {
           ...

I think there are two things to imrove:

  • add these to the mongodb connector dosc
  • MongoDB operations have the prefix $. Even the LB4 supported operations don't need the $, Mongodb users might tend to add the prefix. This issue might be caused by removing the step to clean$ in the buildWhere as @fhsakai suggested. Maybe we can add it back.

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

Successfully merging a pull request may close this issue.

5 participants