title: java mongodb sort() and limit() function
body: <p>I want to sort the returned result for each JSP page(100 items each page),not a global sort.</p>
  
  <pre><code>   DBObject sort = new BasicDBObject();
     DBObject exist = new BasicDBObject();
     DBObject query= new BasicDBObject();
     exist.put("$exists",1);
     query.put("sortKey":exist);//sortKey is not indexed
     sort.put("sortKey",1);
      DBCursor cursor = dbcollection.find(query).limit(100).sort(sort);
      while(cursor.hasNext()){
      System.out.println(cursor.next());
      }
  </code></pre>
  
  <p>But in fact ,the sort is stilled processed for all the documents in the collection,namely ,it is a global sort even though I use function limit(100) .Since the collection is very large-scale , the sort function will take quite a long time.So , I wonder if mongodb java driver has a feature which will perform a local(just sort for the returned 100 documents) instead of global sort?</p>