0

I have data in MongoDB like this

{      
     attribute0
     attribute1
     address:
          [0] :  some data1
          [1] :  some data2
}

the address is of an Array type in MongoDB, and I am using the "address" as sort of a map where a certain value should always go to the index 0, and "1" is the same, for simplicity of the example, let say, if its an email, index 0: is always the receiver, and 1 is the sender.

when I do query conditions like

collection.find ({'meta.addresses[0]': 'some data1'});

I'm not getting any result

so I tried just to do

collection.find ({'meta.addresses': 'some data1'});

And instead, I got result. But this is not what I want since if the "somedata1" value is in index 1, it will still return the result, which is wrong.

How do I do this? I mean query an array element for a certain value

1 Answer 1

2

You can use the dot notation. Try this:

collection.find({'meta.addresses.0': 'some data1'});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.