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

Nested Arrays #19

Closed
gotdan opened this issue Sep 18, 2015 · 5 comments
Closed

Nested Arrays #19

gotdan opened this issue Sep 18, 2015 · 5 comments

Comments

@gotdan
Copy link

gotdan commented Sep 18, 2015

Hi,

It looks like mingo doesn't correctly return values in nested arrays. For example, with this data set:

var data = [{
    key0: [{
        key1: [ {key2: "value2"} ],
        key1a: {key2a: "value2a"}
    }]
}];

The expression {"key0.key1a.key2a": "value2a"} returns the object, while the expression {"key0.key1.key2": "value2"} returns an empty array. Am I constructing the query wrong?

Thanks,
Dan

@kofrasa
Copy link
Owner

kofrasa commented Sep 18, 2015

I think your query should be valid but I have to confirm it with MongoDB's behaviour. I remember there were some limitations with the level of nesting in array queries but the current MongoDB version is 3.0 so things might work differently.

Anyway an equally viable alternative for what you are trying to achieve would be to use the $elemMatch operator such as {"key0.key1": {"$elemMatch": {key2: "value2"}}}

@gotdan
Copy link
Author

gotdan commented Sep 19, 2015

Thanks - I’m not sure $elemMatch will work with this dataset though, since in some cases the value will be an object and and in some the same key will have an array of objects as the value (depending on how many children there are). I don’t have control over the data format, so one of the nice things about the mongo dot notation is that the same query should work in both cases.

Do you know if there is a way to use $elemMatch or another operator to handle this use case?

@kofrasa
Copy link
Owner

kofrasa commented Sep 19, 2015

In that case you could use an $or operator (a bit of a hack i guess) :).

{$or: [
  {"key0.key1": {"$elemMatch": {key2: "value2"}}},
  {"key0.key1.key2": "value2"}
]}

I will look into the bug soon.

kofrasa added a commit that referenced this issue Sep 20, 2015
@kofrasa
Copy link
Owner

kofrasa commented Sep 20, 2015

Just release 0.6.1 that fixes the issue.

@kofrasa kofrasa closed this as completed Sep 20, 2015
@gotdan
Copy link
Author

gotdan commented Sep 21, 2015

Thanks! That was faster than I could implement a work around :).

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