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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With