I'm currently working with the code below:
// Defining my search array
var charArray=['a','b','c']
{
name: 'object1',
myChar: ['a','v','x']
}
{
name: 'object2',
myChar: ['f','h','y']
}
My goal is to retrieve the object that contains a specific value in its attribute.
I thought I could achieve this by doing the following:
db.getCollection('myObjects').find({
'myChar':{
$in:charArray
}
})
However, the response turns out to be null. I also attempted using $elemMatch but it didn't work as expected.
db.getCollection('myObjects').find({
'myChar':{
$elemMatch: {$in: charArray}
}
})