I have data in mondoDB;
db.np_tpy_gla.find({},{"_id":0, "c": 1})
Result:
{ "c" : NumberLong(18) }
{ "c" : NumberLong(40) }
{ "c" : NumberLong(42) }
{ "c" : NumberLong(54) }
...
I am trying to get these values by using Python (pymongo). Here is my code:
counterNumber = cursor.count()
gettingTotalSize = cursor.find({"c": True})
print counterNumber
print gettingTotalSize
and here is result:
115
<pymongo.cursor.Cursor object at 0x13c7890>
I'm tring to get "gettingTotalSize" values one by one.
How can i get these values? i also tried for loop.
Thanks.
EDIT :
I changed my codes like:
gettingTotalSize = cursor.find({}, {"_id": 0, "c": 1})
Vignesh Kalai'codes:
for x in gettingTotalSize :
print x
Here is the new result :
{u'c': 18L}
{u'c': 40L}
{u'c': 42L}
{u'c': 54L}
...
Now I need only the value (18,40,42,54...)
Any ideas? :)
To iterate over a cursor
you could loop over the cursor and to get element out of a dictionary you could pass it's key to get value
Code:
for x in gettingTotalSize :
print x["c"]
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