question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$elemMatch behavior mismatch with MongoDB

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
crcncommented, 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 👍

0reactions
crcncommented, Jul 28, 2021

of course!

Read more comments on GitHub >

github_iconTop Results From Across the Web

date - Result mismatch between elem match, and greater than ...
The elem-match is clearly correct. Attached output. MongoDB shell version: 3.2.1 connecting to: test > db.getCollection('ads') ...
Read more >
How to match $all and equal to conditions in $elemMatch ...
1) Try: - this selecting 2 documents because $in means OR condition in date field, and $all will not work because date inside...
Read more >
$elemMatch (query) — MongoDB Manual
The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria.
Read more >
$ (projection) — MongoDB Manual
The $elemMatch projection operator takes an explicit condition argument. This allows you to project based on a condition not in the query, or...
Read more >
$elemMatch:{$exists: true} - M121 - MongoDB
Looks like the curly braces do not match. I am not to sure that elemmatch … exists give you the expected result.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found