Python操作MongoDB查询时处理ObjectId
从bson中导入ObjectId对象,将字符串转换成id对象查询使用
from bson import ObjectId
import pymongo
conn = pymongo.MongoClient('mongodb://root:abc123@127.0.0.1/admin'
str = "5sdfadsfasdfxzcasdfasdfas"
findinfo = conn.db_name.table_name.find({"_id" : ObjectId(str)})
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »