search by ObjectId in mongodb with pymongo

I need to search an ObjectId with python using pymongo but I always get this error. Any ideas how to search?

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:UsersgerswinDocumentsProyectosDemonio pytest.py", line 2, in <module>
    import pymongo
  File "C:Python27libsite-packagespymongo__init__.py", line 80, in <module>
    from pymongo.connection import Connection
  File "C:Python27libsite-packagespymongoconnection.py", line 39, in <module>
    from pymongo.mongo_client import MongoClient
  File "C:Python27libsite-packagespymongomongo_client.py", line 45, in <module>
    from pymongo import (auth,
  File "C:Python27libsite-packagespymongodatabase.py", line 22, in <module>
    from pymongo.collection import Collection
  File "C:Python27libsite-packagespymongocollection.py", line 25, in <module>
    from pymongo.cursor import Cursor
  File "C:Python27libsite-packagespymongocursor.py", line 19, in <module>
    from bson import RE_TYPE
ImportError: cannot import name RE_TYPE

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I use pymongo 2.4.1.

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x