2024-04-20 06:45:26 发布
网友
我试图从pymongo中删除一条记录,但我无法理解该记录仍在我的连接中的原因。在
这是我的代码:
_id = bottle.request.forms.get('_id') collection.remove({'_id':_id})
\u id变量是我网站中HTML表单的输入文本。下面是remove方法的输出。在
我看不出有什么错误,但这张唱片还在我的收藏中。有什么线索吗?在
您需要先将_id变量(类型为str)转换为ObjectId类型
_id
str
ObjectId
from bson.objectid import ObjectId if type(_id) is not ObjectId: _id = ObjectId(_id)
看看:http://api.mongodb.org/python/2.7rc0/tutorial.html#querying-by-objectid
您需要先将
_id
变量(类型为str
)转换为ObjectId
类型看看:http://api.mongodb.org/python/2.7rc0/tutorial.html#querying-by-objectid
相关问题 更多 >
编程相关推荐