title: How to query nested objects from MongoDB using Spring Boot (REST) and TextQuery?
body: <p>I am writing RESTful API to search MongoDB collection named 'global' by criteria using TextQuery. My problem is that I cannot access nested object fields when doing query. </p>
  
  <p>For example this works:</p>
  
  <pre><code>GET localhost:8080/search?criteria=name:'name'
  </code></pre>
  
  <p>And this does not:</p>
  
  <pre><code>GET localhost:8080/search?criteria=other.othername:'Other Name'
  </code></pre>
  
  <p>I have MongoDB  json structure (imported from JSON into 'global' collection as whole nested objects)</p>
  
  <pre><code>[{
     "name": "Name",
     "desc": "Desc",
     "other" {
       "othername": "Other Name",
  
      }
   },
   {
     "name": "Name",
     "desc": "Desc",
     "other" {
       "othername": "Other Name",
  
      }
   }
  ]
  </code></pre>
  
  <p>And classes (with getters &amp; setters &amp; etc):</p>
  
  <pre><code>@Document(collection="global")
  public class Global{
    @TextIndexed
    String name;
    @TextIndexed
    String desc;
    Other other;
    ...
  }
  
  
  public class Other{
    String othername;
    ...
  }
  </code></pre>
  
  <p>My controller has method</p>
  
  <pre><code>@GetMapping("/search")
   public Iterable&lt;Global&gt; getByCriteria(@RequestParam("criteria") String criteria) {
  ...
  }
  </code></pre>
  
  <p>And I am trying to write text search with </p>
  
  <pre><code>public Iterable&lt;Global&gt; findByCriteria(String criteria) {
          TextCriteria criteria = TextCriteria.forDefaultLanguage().matching(criteria);
          TextQuery query = TextQuery.queryText(criteria);
          return mongoTemplate.find(query, Global.class);
      }
  </code></pre>