【发布时间】:2020-07-02 06:01:07
【问题描述】:
我最近开始使用 Pymongo,现在我想找到在 Response 中删除 $oid 的最佳方法
当我使用find时:
result = db.nodes.find_one({ "name": "Archer" }
并得到响应:
json.loads(dumps(result))
结果是:
{
"_id": {
"$oid": "5e7511c45cb29ef48b8cfcff"
},
"about": "A jazz pianist falls for an aspiring actress in Los Angeles."
}
我的预期:
{
"_id": "5e7511c45cb29ef48b8cfcff",
"about": "A jazz pianist falls for an aspiring actress in Los Angeles."
}
如您所见,我们可以使用:
resp = json.loads(dumps(result))
resp['id'] = resp['id']['$oid']
但我认为这不是最好的方法。希望大家有更好的解决方案。
【问题讨论】:
标签: pymongo pymongo-3.x flask-pymongo