收藏:progs
{ "_id" : "ABC", "defaultDirectory" : "abc", "defaultRecvDirectory" : "abc" }
{ "_id" : "RAS", "defaultRecvDirectory" : "recv/ras" }
{ "_id" : "SND", "defaultSendDirectory" : "send/snd" }
在 mongo 控制台中:
db.progs.find({"_id":{"$lt":"ZZZZZZZZZ"}}).sort({"_id":-1}).limit(1);
==> { "_id" : "SND", "defaultSendDirectory" : "send/snd" }
在 Java 中:
BasicDBObject query = new BasicDBObject();
query.put("_id", new BasicDBObject("$lt", "ZZZZZZZZZZ"));
DBCursor cursor = collection.find(query).sort(new BasicDBObject("_id","-1")).limit(1);
for (DBObject dbObject : cursor) {
System.out.println(dbObject);
}
==> { "_id" : "ABC", "defaultSendDirectory" : "abc", "defaultRecvDirectory" : "abc" }
有人可以解释其中的区别吗?