Return python object rather than dictionary for `find` method

I wander if there are some features in pymongo which enable attribute-like access in the query result.

For example, I want:

doc = col.find_one({"key": "value"})
print(doc.key) # => "value"

It seems that current API does not support it (which returns python dictionary, instead), or I’ve not carefully read the documentation.
Thanks for all your generous helps!

Hello @sn_w,

The findOne method returns a document or null. In PyMongo it is the same as specified at find_one.

To get the value of a field you have to the print(doc.key) # => "value". But, you can use projection in the query to retrieve limited fields from the document.

There are ORM like tools which are listed at Tools - PyMongo - this might be something you are looking for.

To print a value in python the syntax is different from JavaScript. You must say doc[key].