python判断mongo查询结果是否为空,可使用cursor.count()来判断,为0则查询返回结果为空。python
conn = pymongo.MongoClient(host="192.168.3.6",port=27017)app
db = conn.testdbide
db.authenticate("appuser","apppass")it
mylog = db.system.profile
a = mylog.find({"ts":{'$gt':tn}}).sort("ts",pymongo.ASCENDING)
if a.count() == 0:class
print "查询结果为空"test
else:file
for i in a:查询
print isort