我正在尝试从名为prob
的mongo数据库集合中获取nr
的最高值,该集合现在如下所示:
{
"_id": {
"$oid": "5ae9d062f36d282906c59736"
},
"nr": 1,
"nume": "numeunu",
"enunt": "-",
"datedeintrare": "-",
"datedeiesire": "-"
}
{
"_id": {
"$oid": "5ae9f190f36d282906c5b461"
},
"nr": 2,
"nume": "numedoi",
"enunt": "-",
"datedeintrare": "-",
"datedeiesire": "-"
}
我的测试代码是:
@app.route('/test')
def testaree():
prob = mongo.db.prob
return prob.find().sort({"nr":-1}).limit(1)
但它给了我一个错误TypeError: if no direction is specified, key_or_list must be an instance of list
使用pymongo进行排序的语法与mongo查询语言不同。 在上面的代码中使用的表达式是
但是,这是mongo shell查询语法。使用pymongo时
在对数据进行排序后,还可以使用find\ one而不是limit子句。你知道吗
相关问题 更多 >
编程相关推荐