I need get documents from db by oid, like:
Docs.objects(_id='4f4381f4e779897a2c000009')
But how to do it, if _id requires ObjectId object and even I try to set ObjectId from pymongo it doesn't work.
Docs.objects(_id=pymongo.objectid.ObjectId('4f4381f4e779897a2c000009'))
return empty list
The connect() function returns a MongoClient object. Using list_database_names() method available to this object, we can retrieve number of databases on the server. It is also possible to obtain list of collections in a database, using list_collection_names() method.
The Object ID is located in the Identity section on the right. Find role assignments by selecting Access control (IAM) in the left menu, then Role assignments.
MongoDB provides a function with the name findById() which is used to retrieve the document matching the 'id' as specified by the user. In order to use findById in MongoDB, find() function is used. If no document is found matching the specified 'id', it returns null.
Both PyMongo and MongoEngine can be used to access data from a MongoDB database. However, they work in very different ways and offer different features. PyMongo is the MongoDB recommended library. It makes it easy to use MongoDB documents and maps directly to the familiar MongoDB Query Language.
This should work:
Docs.objects(pk='4f4381f4e779897a2c000009')
How about just using the raw string:
Docs.objects.get(id='4f4381f4e779897a2c000009')
That is probably the easiest way ... right ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With