How can I do a quick find() or findOne() with mongoengine, I already have this but it does not seems to be the right way:
Cars.objects()._collection.find_one({'model':2013})
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]
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