如何使用Python获取cursor对象的值

2024-09-29 05:22:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我在蒙多布有数据

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…)

有什么想法吗?:)


Tags: 数据代码iddbcountnpfindcursor