0

I need to create a query that searches within an array for occurrences of values that pass through an array.

It does not need to be an exact query, but it can bring me the occurrences

This is a part of my model

var OrdersCompaniesSchema = new Schema({
    target_studies: String,
    target_grade: String,
    interests : [String], // Contains for example ["Works","Sciences","Economy"]
    stock: Number
})

I tried the query like this

db.orderscompanies.find({"interests": { "$in": ["Works","Banks","Sports"] }})

But this query response me a blank array [] because this find the exactly values, and I dont need this. I need find any one ocurrence according the array with which I am consulting

Any help? Thanks!

1 Answer 1

2

According to the MongoDB docs here. It states that If the field holds an array, then the $in operator selects the documents whose field holds an array that contains at least one element that matches a value in the specified array. It doesn't try to match all occurrences as per your question.

It should work for you. If not, you should be doing some other mistake. If you can put more concrete code it'll help!

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.