1

Suppose there is a Schema and there is a field

 phoneNumber:{
    type:[String],
    required:true
},

now i want to compare this column with an array , example ["ABC","DEF"]. How can i check if any element in this array matches with an element in a document

Like if there are documents A =  { phoneNumber :["ACD, "BFG"]} and B= {phoneNumber:["GCD"]} 

The query should return the B document if i check using C= ["GCD"], as B is the only document that contains "GCD" element. I did try to use myDoc.find({phoneNumber:{$in:["GCD"]}) but it isnt returning anything. What is the correct query which is to be used

1
  • Your question is not clear to me. Please format your post and clearly show each document separately and data in each document. Commented May 28, 2020 at 13:26

1 Answer 1

2

Use $in:

db.collection.find({"phoneNumber.type": { $in: ["ACD", "BFG"] } })
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.