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

php - Wordpress: Link a post to posts of another category manually -

delphi xe7 upload/download dropbox file using the rest client and show progress -

java - Get more than One value and display it -