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