Response response = client.query(new Query("test", "testQuery", 0, 100,
new BasicBSONObject("$query",new BasicBSONObject())
.append("$orderby", new BasicBSONObject("_id", 1))));
Assert.assertEquals(100, response.getNumberReturned());
for (int i = 0; i < 100; i++) {
BSONObject doc = response.getDocuments().get(i);
Assert.assertEquals(i, doc.get("_id"));
}
// order integer (reversed)
response = client.query(new Query("test", "testQuery", 0, 100,
new BasicBSONObject("$query", new BasicBSONObject())
.append("$orderby", new BasicBSONObject("_id", -1))));
Assert.assertEquals(100, response.getNumberReturned());
for (int i = 0; i < 100; i++) {
BSONObject doc = response.getDocuments().get(i);
Assert.assertEquals(99-i, doc.get("_id"));
}
}