find() and findOne() in mongoengine find() and findOne() in mongoengine mongodb mongodb

find() and findOne() in mongoengine


For find() you can do:

Cars.objects(model=2013)

And for find_one() you can do:

Cars.objects.get(model=2013)

To retrieve a result that should be unique in the collection, use get(). This will raise DoesNotExist if no document matches the query, and MultipleObjectsReturned if more than one document matched the query.

Else if multiple records exists, simply limit, like:

Cars.objects(model=2013)[0]