下面的mongodb查询会将最近的条目返回到集合
number = 1004123
print(number)
string = "{:,}".format(number)
print(string)
有人知道如何在Java中实现此查询吗?
答案 0 :(得分:4)
使用Mongo-Java Driver,此代码就是一个例子:
MongoClient client = new MongoClient("localhost",27017);
MongoDatabase db = client.getDatabase("test");
MongoCollection<Document> collection = db.getCollection("RSS");
FindIterable<Document> it = collection.find().limit(6).sort(new Document().append("$natural", -1));
MongoCursor<Document> cursor = it.iterator();
while(cursor.hasNext()){
Document doc = cursor.next();
System.out.println(doc.toJson());
}