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

$elemMatch behavior mismatch with MongoDB #228

Closed
nabati opened this issue Jul 20, 2021 · 6 comments
Closed

$elemMatch behavior mismatch with MongoDB #228

nabati opened this issue Jul 20, 2021 · 6 comments

Comments

@nabati
Copy link

nabati commented Jul 20, 2021

Similar to #227, there seems to be another mismatch for $elemMatch compared to MongoDB behavior.

Specifying $elemMatch as a string is handled by sift when it should not be.

  it("should not handle $elemMatch with string value", () => {
    expect(
      sift({ responsible: { $elemMatch: "Poyan" } })({
        responsible: ["Poyan", "Marcus"],
      })
    ).toEqual(false);
  }); 

// --> test case fails, sift called with test-data returns true

Attempting to run the same query against MongoDB returns $elemMatch needs an Object, which is also what the documentation specifies.

https://docs.mongodb.com/manual/reference/operator/query/elemMatch/

Please advise.

@crcn
Copy link
Owner

crcn commented Jul 27, 2021

This should be addressed in v14.0.0. Let me know if you're still experiencing this issue!

@nabati
Copy link
Author

nabati commented Jul 28, 2021

Tested with 14.0.0.

The new version of the package no longer returns true for this case, but rather returns false.

This makes more sense, but I think it would be more consistent if it threw an error, like #227 does and like MongoDB does. What do you think? @crcn

image

@crcn
Copy link
Owner

crcn commented Jul 28, 2021

This makes more sense, but I think it would be more consistent if it threw an error, like #227 does and like MongoDB does. What do you think? @crcn

Yes good idea 👍

@crcn
Copy link
Owner

crcn commented Jul 28, 2021

fixed & published to NPM as 14.0.1

@nabati
Copy link
Author

nabati commented Jul 28, 2021

thank you! 🧡

@nabati nabati closed this as completed Jul 28, 2021
@crcn
Copy link
Owner

crcn commented Jul 28, 2021

of course!

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