Earlier I used to use count() when I used to have a simple function of finding any product for example :
grocery = grocery.find({'Product':{'$regex':'.*?'+resultx,'$options':"i"}})
and then use the count() function on it to get the count like so which worked perfectly fine in giving me the count :
grocery.count() == 0:
But now I am using aggregate like so :
pipeline = [{'$match': {'Product':{'$regex':'.*?'+resultx,'$options':"i"}}},
{'$lookup':{'from': 'othervendors','localField': 'Product','foreignField': 'Product','as': 'Matches'}}]
grocery = db.products.aggregate(pipeline)
and if I use count() on it :
grocery.count() == 0:
It throws me an error :
**AttributeError: 'CommandCursor' object has no attribute 'count'**
My question is, How do I use count() on the aggregate function