[英]PyMongo returns float instead of integer
我在Mongo中有一個存儲URL的集合,為此,我使用以下字段:
在mongo客戶中,我執行
db.myCollection.find()
它返回
{"protocol" : "https", "host" : "google.com", "port" : 80}
在帶有PyMongo的Python中,我執行
for service in myCollection.find():
print service['port']
它返回
80.0
我的數字存儲為整數嗎?
使用PyMongo,如何將其返回為整數而不是浮點數?
您可以將其轉換為整數,如下所示:
for service in myCollection.find():
print int(service['port'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.