Python操作MongoDB查询时处理ObjectId

2019-12-24T10:16:10

从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)})
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »