سؤال

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