On Django we can use the QuerySet.exists()
to check if an object exists in the DB in the most efficient way, without actually fetching the record.
Is there an equivalent function on Mongoengine?
According to official documentation, here is solution how to make this if you have object id.Its the best solution for your case, that i have seen in mongoengine documentation.It works as below:
# Returns None or Object if it exists
result = Collection.objects.with_id(object_id=*your object id*)
if result is None:
# raise error
else:
# make some actions with this object
Is this is what are you looking for?
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