How to query by ObjectId in Motor in tornado

Question:

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

Asked By: neoeahit

||

Answers:

Import ObjectId from bson:

import motor
from bson import ObjectId

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