Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find elements in a collection where an element has a field which is a list and a given value must belong to the list

I would like to query the objects in my collection such as a given value must belong to the values in the stringArray

stringArray is the name of the field for each Obejct that contains a list of Strings

the strucutre of my collection in mongodb is

Object1
{
  field1
  field2
  stringArray[2] 
        0     String0
        1     String1
}

Object2
{
  field1
  field2
  stringArray[3] 
        0     String0
        1     String1
        2     String2
}

}

My query is:

     Query query = new Query();
     query.addCriteria(
            Criteria.where(theValueIamlookingFor).in("stringArray")                
     );               
    return mongoTemplate.find(query, myObject.class);

So far, it hasn't worked.

Any ideas ?

like image 699
Makoto Avatar asked Jan 21 '14 14:01

Makoto


1 Answers

Think you have just flipped there order. Please try:

Criteria.where("stringArray").in(theValueIamlookingFor)

instead of the above

like image 74
Ori Dar Avatar answered Oct 04 '22 01:10

Ori Dar