Question

I'm trying to do a find within a MongoDB collection using the Pymongo python driver.

I'm using a key called "book id" which has a datatype of "int64", however the docs only mention the ability to search for documents that contain "book id" with an int64 datatype. e.g.

 db.books.find( { "book id": { $type : 18 } })

How can I perform the same search using Python and also include the key value to search for. e.g.

"book id": 12345
Was it helpful?

Solution

Numeric types are the one case where MongoDB will do the conversion for you. As such, you don't need to do anything special for int64 fields:

db.books.find({ "book id": 12345 })
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top