title: Spring Data MongoDB get document by inner object
body: <p>In my Spring Boot / Spring Data MongoDB project I have a following POJO:</p>
  
  <pre><code>@Document(collection = "decision_analysis")
  public class DecisionAnalysis {
  
      private String id;
  
      private DecisionAnalysisRequest decisionAnalysisRequest;
  
      private DecisionMatrixPageResponse decisionMatrixPage;
  
      private Date createDate;
  
      private HttpRequestData httpRequestData;
  
  ...
  
  }
  </code></pre>
  
  <p>where <code>DecisionAnalysisRequest</code>:</p>
  
  <pre><code>public class DecisionAnalysisRequest implements Serializable {
  
      private static final long serialVersionUID = 1493180175756424789L;
  
      private String decisionNameFilterPattern;
  
      private Set&lt;BaseQuery&gt; filterQueries;
  
      private Set&lt;Long&gt; sortCriteriaIds;
  
      private String sortWeightCriteriaDirection;
  
      private String sortTotalVotesCriteriaDirection;
  
      private Map&lt;String, Double&gt; sortCriteriaCoefficients;
  
      private Long sortCharacteristicId;
  
  ...
  
  }
  </code></pre>
  
  <p>I need to lookup <code>DecisionAnalysis</code> documents by <code>DecisionAnalysisRequest</code> so I have created a Spring Data MongoDB repository with the following method:</p>
  
  <pre><code>@Repository
  public interface DecisionAnalysisRepository extends MongoRepository&lt;DecisionAnalysis, String&gt; {
  
      DecisionAnalysis findByDecisionAnalysisRequest(DecisionAnalysisRequest decisionAnalysisRequest);
  
  }
  </code></pre>
  
  <p>Right now this method only work when <code>filterQueries</code> is null. But when <code>filterQueries</code> is not null the method continuously returns no results.</p>
  
  <p><code>filterQueries</code> is an array of composite objects, for example:</p>
  
  <pre><code> "filterQueries":[
        {
           "type":"AnyInQuery",
           "characteristicId":711903,
           "characteristicName":"Body type",
           "value":[
              "Compact"
           ],
           "operator":"OR"
        },
        {
           "type":"RangeQuery",
           "characteristicId":712745,
           "characteristicName":"Sensor photo detectors (megapixels)",
           "value":[
              10,
              53
           ]
        }
     ]
  </code></pre>
  
  <p>What am I doing wrong and how do I adjust my code in order to properly look up <code>DecisionAnalysis</code> documents by <code>DecisionAnalysisRequest</code> even when the <code>filterQueries</code> contains data.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is a sample <code>DecisionAnalysisRequest</code> document that I'm going to use as a key(information inside of this document varies each time per user selected on UI):</p>
  
  <pre><code>{
     "sortCriteriaIds":[
        711882,
        711887,
        711884,
        711899,
        711896,
        711897,
        711890,
        711891,
        711888,
        711889,
        711895,
        711892,
        711893
     ],
     "sortCriteriaCoefficients":{
  
     },
     "pageNumber":0,
     "pageSize":10,
     "sortWeightCriteriaDirection":"DESC",
     "sortid":null,
     "sortCharacteristicDirection":null,
     "sortDecisionPropertyName":null,
     "sortDecisionPropertyDirection":null,
     "decisionsIds":[
  
     ],
     "persistent":true,
     "includeChildids":null,
     "excludeChildids":null,
     "filterQueries":[
        {
           "type":"AnyInQuery",
           "characteristicId":711913,
           "characteristicName":"Body material",
           "value":[
              "Aluminium alloy",
              "Brass",
              "Carbon fiber"
           ],
           "operator":"OR"
        },
        {
           "type":"AnyInQuery",
           "characteristicId":711903,
           "characteristicName":"Body type",
           "value":[
              "Compact SLR",
              "Compact"
           ],
           "operator":"OR"
        },
        {
           "type":"EqualQuery",
           "characteristicId":712746,
           "characteristicName":"Sensor size",
           "value":"1/1.7\" (7.44 x 5.58 mm)"
        },
        {
           "type":"AnyInQuery",
           "characteristicId":712895,
           "characteristicName":"Color space",
           "value":[
              "Adobe RGB",
              "ECI RGB",
              "Primary color space"
           ],
           "operator":"OR"
        },
        {
           "type":"AnyInQuery",
           "characteristicId":712145,
           "characteristicName":"Other resolutions",
           "value":[
              "1008 x 672",
              "1024 x 1024",
              "1024 x 576"
           ],
           "operator":"OR"
        },
        {
           "type":"AnyInQuery",
           "characteristicId":712738,
           "characteristicName":"Image ratio w:h",
           "value":[
              "1:1",
              "3:2",
              "4:3"
           ],
           "operator":"OR"
        },
        {
           "type":"RangeQuery",
           "characteristicId":712744,
           "characteristicName":"Effective pixels (megapixels)",
           "value":[
              9,
              44
           ]
        },
        {
           "type":"EqualQuery",
           "characteristicId":712901,
           "characteristicName":"Color filter array",
           "value":"RGB color filter array"
        },
        {
           "type":"EqualQuery",
           "characteristicId":712921,
           "characteristicName":"Image stabilization",
           "value":"Sensor-shift"
        },
        {
           "type":"AnyInQuery",
           "characteristicId":712944,
           "characteristicName":"Uncompressed format",
           "value":[
              "No",
              "RAW",
              "TIFF"
           ],
           "operator":"OR"
        },
        {
           "type":"AnyInQuery",
           "characteristicId":712928,
           "characteristicName":"Image parameters",
           "value":[
              "Brightness",
              "Color",
              "Color Space",
              "Color Tone",
              "Contrast"
           ],
           "operator":"OR"
        },
        {
           "type":"RangeQuery",
           "characteristicId":712919,
           "characteristicName":"White balance presets",
           "value":[
              2,
              10
           ]
        },
        {
           "type":"RangeQuery",
           "characteristicId":712917,
           "characteristicName":"Boosted ISO (minimum)",
           "value":[
              1762,
              10741
           ]
        },
        {
           "type":"AnyInQuery",
           "characteristicId":712950,
           "characteristicName":"File format",
           "value":[
              "3FR",
              "AGIF",
              "ARW"
           ],
           "operator":"OR"
        },
        {
           "type":"RangeQuery",
           "characteristicId":712918,
           "characteristicName":"Boosted ISO (maximum)",
           "value":[
              339298,
              2878034
           ]
        },
        {
           "type":"RangeQuery",
           "characteristicId":713340,
           "characteristicName":"Normal focus range (cm)",
           "value":[
              22,
              131
           ]
        },
        {
           "type":"EqualQuery",
           "characteristicId":713343,
           "characteristicName":"Lens mount",
           "value":"Leica M"
        },
        {
           "type":"AnyInQuery",
           "characteristicId":713325,
           "characteristicName":"Autofocus",
           "value":[
              "Center",
              "Continuous",
              "Contrast Detect (sensor)",
              "Face Detection",
              "Live View"
           ],
           "operator":"OR"
        },
        {
           "type":"RangeQuery",
           "characteristicId":713341,
           "characteristicName":"Macro focus range (cm)",
           "value":[
              19,
              75
           ]
        },
        {
           "type":"RangeQuery",
           "characteristicId":713342,
           "characteristicName":"Number of focus points",
           "value":[
              78,
              468
           ]
        },
        {
           "type":"RangeQuery",
           "characteristicId":713388,
           "characteristicName":"Viewfinder resolution (dots)",
           "value":[
              633548,
              3722581
           ]
        },
        {
           "type":"RangeQuery",
           "characteristicId":713386,
           "characteristicName":"Viewfinder coverage %",
           "value":[
              84,
              97
           ]
        }
     ]
  }
  </code></pre>