Вопрос

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
Это было полезно?

Решение

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 })
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top