programing

pymongo를 사용하여 mongodb에서 ObjectId로 검색

nicescript 2023. 2. 15. 22:29
반응형

pymongo를 사용하여 mongodb에서 ObjectId로 검색

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)})]

언급URL : https://stackoverflow.com/questions/16073865/search-by-objectid-in-mongodb-with-pymongo

반응형