title: UncategorizedMongoDbException: Query failed with error code 2 and error message 'unknown top level operator: $gte'
body: <p>Why I am facing this exception?</p>
  
  <pre><code>javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 2 and error message &amp;apos;unknown top level operator: $gte&amp;apos; on server localhost:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 2 and error message &amp;apos;unknown top level operator: $gte&amp;apos; on server localhost:27017
  at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
  at org.eclipse.jetty.server.Server.handle(Server.java:564)
  at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
  at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
  at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
  at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
  at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
  at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
  at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
  at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
  at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
  at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
  at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>Without this code works fine:</p>
  
  <pre><code>public List&lt;Model&gt; getByPeriod(String field, Date from, Date to) {
      return mongo.find(new Query(Criteria.where(field).gte(from)
              .and(field).lt(to)), getModelClass());
  }
  </code></pre>
  
  <p>Fails also for</p>
  
  <pre><code>//...
  .where(field).gte(from).lt(to)//...
  </code></pre>
  
  <p>But similar code works fine for other cases.</p>