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

javascript - Complete OpenIDConnect auth when requesting via Ajax -

c# - Replace text in MailItem Body -

java - Get more than One value and display it -