pymongo - how to test for empty mongodb query in pymong -


how test query no results in pymongo?

 x = collection.find( { "$and" : [ { "$or" : [ {"template":"template3.1"} , {"type" : "gift"} ] }, {"to":"test@test.com"} ] } ) 

can test if x has returned nothing before doing data?

use cursor method count() check number of documents in cursor.

if x.count()>0:     //use cursor 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -