我的mongo db中有以下对象:
{
"type" : "timetype"
"time" : "18"
}
{
"type" : "timetype"
"time" : "5"
}
{
"type" : "timetype"
"time" : "43"
}
{
"type" : "timetype"
"time" : "23"
}
我的java代码如下:
BasicDBObject query = new BasicDBObject();
query.put("type", "timetype");
//I don't know what to put in the (...)
DBCursor cursor = Collection.find(query).sort(...).limit(1);
我想在我的mongo数据库中找到满足查询参数的最短时间的条目,但是我不知道该怎样排序才能实现这一点。
答案 0 :(得分:3)
的内容
Collection.find(query).sort(new BasicDBObject( "time" , 1 )).limit(1);
应该有用。