3

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

neoeahit
  • 1,689
  • 2
  • 21
  • 35

1 Answers1

5

Import ObjectId from bson:

import motor
from bson import ObjectId

cursor = collection.find({ "_id": ObjectId('54b89db31d41c8159742d65a') })
Roj
  • 995
  • 1
  • 8
  • 22
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317