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

Incorrect behavior with dotted path query on nested arrays #238

Closed
cmlenz opened this issue Apr 29, 2022 · 3 comments
Closed

Incorrect behavior with dotted path query on nested arrays #238

cmlenz opened this issue Apr 29, 2022 · 3 comments
Labels

Comments

@cmlenz
Copy link

cmlenz commented Apr 29, 2022

I ran into the following query working on the MongoDB playground, but not working in Mingo:

  const query = new Query({'children.children.flags': 'foobar'});
  const result = query.test({
    "children": [
      {
        "children": [
          {
            "flags": ["foobar"],
          },
        ],
      },
      {
        "children": [
          {
            "flags": [],
          },
        ],
      },
    ],
  });

  expect(result).toBe(true); // ❌ fails

Here's the link to the playground: https://mongoplayground.net/p/NTqxvjkqAEh. Here I am getting the expected result.

With Mingo, the query does not match.

When I remove one level of nesting and adjust the query, the test passes:

  const query = new Query({'children.flags': 'foobar'});
  const result = query.test({
    "children": [
      {
        "flags": ["foobar"],
      },
      {
        "flags": [],
      },
    ],
  });

  expect(result).toBe(true); // ✅ works

It also matches when I remove the second child!

  const query = new Query({'children.grandchildren.flags': 'foobar'});
  const result = query.test({
    "children": [
      {
        "grandchildren": [
          {
            "flags": [
              "foobar",
            ],
          },
        ],
      },
    ],
  });

  expect(result).toBe(true); // ✅ works

Is this a bug or am I misunderstanding / misconfiguring?

@kofrasa kofrasa added the bug label Apr 29, 2022
@kofrasa
Copy link
Owner

kofrasa commented Apr 29, 2022

Thanks for the bug report. We are not correctly handling deeply nested array comparisons here. The array should be flattened to the depth of the selector before comparing.

@cmlenz
Copy link
Author

cmlenz commented Apr 29, 2022

Wow, that was quick. It works now. Thanks a lot!

@kofrasa
Copy link
Owner

kofrasa commented Apr 29, 2022

You are welcome.

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

No branches or pull requests

2 participants