如何在python循环中迭代mongo游标 [英] how to Iterate a mongo cursor in a loop in python

查看:127
本文介绍了如何在python循环中迭代mongo游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遍历python中的循环,但嵌套循环未到达增量元素.

I am trying to iterate through a loop in python but the nested loop is not reaching the incremental element.

除了像range以外,还有其他方法吗?

Is there any way other than using range like "hasNext()"?

cursor1 = Collection.find({x : {"$gt" : 1}})
array1 = []
array2 = []
print Collection.count()

for r in range(0, cursor1.count()):
    first = cursor1.next().get("entity")
    array2.append()

    for z in range(len(array2)):
        print len(original_tweets)
        if originalEntity.get("id") != duplicated_entity("id"):
            array2.append(second)

推荐答案

就像您自然地对游标对象进行迭代一样,我看不到您要使用range.next()对其进行迭代. >

Just iterate as you naturally would over cursor objects, I don't see you would want to iterate over it using range and .next().

cursor1= Collection.find({x : {"$gt" : 1}})
for record in cursor1:
    # do stuff with your record

这篇关于如何在python循环中迭代mongo游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆