1. 问题:
使用sort排序,代码如下:
db.test.find().sort({"name" : 1, "age" : 1})
遇到如下异常:
TypeError: if no direction is specified, key_or_list must be an instance of list
解决方法:
db.test.find().sort([("name", 1), ("age" , 1)])
原因:在python中只能使用列表进行排序,不能使用字典
2. 问题:
通过http请求ObjectId来进行数据操作时,无法查找到数据,比如:
/posts/50b3bda58a02fb9a84d8991e
解决方法:
在后台接受到ObjectId后,对其实例化即可:
from bson.objectid import ObjectId
objectId = ObjectId(str(_id))
参考文档: