Reputation: 7520
I have a collection in Mongo in which I store URLs, for that I use the following fields:
In mongo client I execute
db.myCollection.find()
and it returns
{"protocol" : "https", "host" : "google.com", "port" : 80}
In Python with PyMongo I execute
for service in myCollection.find():
print service['port']
and it returns
80.0
Is my number stored as integer?
Using PyMongo, how can I return it as integer and not float?
Upvotes: 3
Views: 3327
Reputation: 14714
From the docs:
By default, the mongo shell treats all numbers as floating-point values. The mongo shell provides the NumberInt() constructor to explicitly specify 32-bit integers.
I guess value is stored as float.
Related: https://stackoverflow.com/a/30501514/4653485
Upvotes: 5
Reputation: 4171
you can cast it to integer like this:
for service in myCollection.find():
print int(service['port'])
Upvotes: 0