This is the version I used :
pymongo 3.9.0,
mongoengine-0.18.2,
python 3.7.1
I have a simple Document
like below:
class MyModel(Document):
meta = {"collection": "my_model"}
name = StringField()
email = StringField()
address = StringField()
I want to check whether a record
is exists by using the name
,email
or address
.I follow this docs
Therefore I run this query:
user = MyModel.objects(Q(name="myname") | Q(email="abc@mail.com") | Q(address="1234567"))
if user.count() > 0:
print "User Existed"
But the result is always return true,which is User already existed
,even the collection is empty one.
I also tried if user is None
,but the result is still the same.I think is because it always will return a object whether have result or not.
So my question is, how can I check whether a query is returning result or empty result?