Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python determines whether the result returned by the database is empty.

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Python can use cursor.count () to determine whether the mongo query result is empty, and if it is 0, the query return result is empty.

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 "query result is empty"

Else:

For i in a:

Print i

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report