python判断mongo查询结果是否为空,可以使用cursor.count()来判断,为0则查询返回结果为空。
conn = pymongo.MongoClient(host="192.168.3.6",port=27017)
db = conn.testdb
db.authenticate("appuser","apppass")
mylog = db.system.profile
a = mylog.find({"ts":{‘$gt‘:tn}}).sort("ts",pymongo.ASCENDING)
if a.count() == 0:
print "查询结果为空"
else:
for i in a:
print i
时间: 2024-10-16 01:21:10