public class Test {
|
public static void main(String[] args) throws UnknownHostException {
|
Mongo m = new Mongo();
|
DBCollection collection = m.getDB("test").getCollection("tmp");
|
collection.drop();
|
collection.ensureIndex("length");
|
for (int i = 0; i < 10; i++) {
|
DBObject object = new BasicDBObject("_id", i);
|
object.put("length", (int) (Math.random() * 100));
|
collection.insert(object);
|
}
|
DBCursor cursor = collection.find().addSpecial("$max", new BasicDBObject("length", 10));
|
System.out.println("cursor.count - " + cursor.count());
|
System.out.println("cursor.toArray.size - " + cursor.toArray().size());
|
}
|
}
|