简体   繁体   中英

How to query by ObjectId in Motor in tornado

I am trying to use tornado, and my use case is to query by the object ID.

I have seen examples and ref's to query by anything else, but the ObjectID. since it is unique, I want to use it instead to query.

Any suggestions how to use the ObjectId for querying using motor

Pymongo is a dependency of motor , so I't not like you are pulling in anything additional. Just import the ObjectId method as normal and use it in your query:

 import motor
 from bson.objectid import ObjectId

 cursor = collection.find({ "_id": ObjectId('54b89db31d41c8159742d65a') })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM