mongo的主键id与字符串的相互转换

from bson.objectid import ObjectId

1、字符串转ObjectId

oid = ObjectId(id_str);

2、ObjectId转字符串

id_str = ObjectId(id).toString()


例子
find({'_id': ObjectId(id_str)})
原文地址:https://www.cnblogs.com/itBlogToYpl/p/12762067.html