我在蒙多布有数据
db.np_tpy_gla.find({},{"_id":0, "c": 1})
结果:
{ "c" : NumberLong(18) }
{ "c" : NumberLong(40) }
{ "c" : NumberLong(42) }
{ "c" : NumberLong(54) }
...
我试图通过使用Python(pymongo)来获取这些值。 这是我的代码:
counterNumber = cursor.count()
gettingTotalSize = cursor.find({"c": True})
print counterNumber
print gettingTotalSize
结果是:
115
<pymongo.cursor.Cursor object at 0x13c7890>
我想一个接一个地得到“gettingTotalSize”值。
我怎样才能得到这些价值观?我也试过循环。
谢谢。
编辑:
我把密码改成:
gettingTotalSize = cursor.find({}, {"_id": 0, "c": 1})
Vignesh Kalai代码:
for x in gettingTotalSize :
print x
以下是新的结果:
{u'c': 18L}
{u'c': 40L}
{u'c': 42L}
{u'c': 54L}
...
现在我只需要值(18,40,42,54…)
有什么想法吗?:)
要在
cursor
上迭代,可以在游标上循环,并从字典中获取元素,可以传递获取值的键代码:
相关问题 更多 >
编程相关推荐