1

I want to figure out how to search object array, which has label "작성" and value is "Y"
I made find query like this {"attrs.label": "작성" , "attrs.value": "Y"}
But the problem is {..., attrs: [{label: "작성", value: "N"}, {label: "Another", value: "Y"}]}
this document was matched with my query I need full match in one array element.

I tried

{ $and: [{"attrs.label": /작성/}, {"attrs.value": "Y"}]}

1 Answer 1

1

In such case you can use $elemMatch operator to indicate that at least one array item has to fullfill all the requirements:

db.collection.find({ attrs: { $elemMatch: { label: "작성", value: "Y" } } })

Mongo Playground

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.