0

I have the following code

//My search array
var charArray=['a','b','c']

{
    name: 'object1',
    myChar: ['a','v','x']
}

{
    name: 'object2',
    myChar: ['f','h','y']
}

I want to get the object which contains a value in its attribute.

I hope to get the first object using this:

db.getCollection('myObjects').find({
    'myChar':{
        $in:charArray
    }
})

The response is null. In fact I tried using $elemMatch without success

db.getCollection('myObjects').find({
    'myChar':{
        $elemMatch: {$in: charArray}
    }
})
chazsolo
  • 7,873
  • 1
  • 20
  • 44
Josema Pereira
  • 101
  • 1
  • 8

1 Answers1

-1

I thing you have a typo because I replicate your situation in mongodb instance and your $elemMatch solution works just fine.

Diego Maia
  • 40
  • 3