gpt4 book ai didi

python - 使用 pymongo 在 mongodb 中按 ObjectId 搜索

转载 作者:太空宇宙 更新时间:2023-11-03 20:20:08 26 4
gpt4 key购买 nike

我需要使用 pymongo 使用 python 搜索 ObjectId,但总是收到此错误。有什么想法如何搜索吗?

import pymongo
from pymongo import MongoClient
from pymongo import ObjectId

gate = collection.find({'_id': ObjectId(modem["dis_imei"])})
print gate

Traceback (most recent call last):
File "C:\Users\gerswin\Documents\Proyectos\Demonio py\test.py", line 2, in <module>
import pymongo
File "C:\Python27\lib\site-packages\pymongo\__init__.py", line 80, in <module>
from pymongo.connection import Connection
File "C:\Python27\lib\site-packages\pymongo\connection.py", line 39, in <module>
from pymongo.mongo_client import MongoClient
File "C:\Python27\lib\site-packages\pymongo\mongo_client.py", line 45, in <module>
from pymongo import (auth,
File "C:\Python27\lib\site-packages\pymongo\database.py", line 22, in <module>
from pymongo.collection import Collection
File "C:\Python27\lib\site-packages\pymongo\collection.py", line 25, in <module>
from pymongo.cursor import Cursor
File "C:\Python27\lib\site-packages\pymongo\cursor.py", line 19, in <module>
from bson import RE_TYPE
ImportError: cannot import name RE_TYPE

最佳答案

我使用 pymongo 2.4.1。

from bson.objectid import ObjectId
[i for i in dbm.neo_nodes.find({"_id": ObjectId(obj_id_to_find)})]

关于python - 使用 pymongo 在 mongodb 中按 ObjectId 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58217646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com