不知道這裏或爲什麼發生了什麼,似乎當我在一個遊標上進行迭代時它會移動它,因爲我無法從相同的起點運行第二個循環。我的例子:迭代在PyMongo中移動光標?
players = db.player.find({'parent_api__id' : 'stats', 'game__id':{'$in':games_list}, "played":"true"});
count = 0;
for c in players:
count = count + 1
for c in players:
game = db.game.find_one({'parent_api__id':'schedule', 'id':c['game__id']})
c['date'] = game['scheduled']
print c
在這一個它從未進入第二循環,如果我把打印上去頂它永遠不會打它,它從來不會在底部
打印C現在如果我評論出在它的計數循環,所以它看起來是這樣的:
players = db.player.find({'parent_api__id' : 'stats', 'game__id':{'$in':games_list}, "played":"true"});
#count = 0;
#for c in players:
# count = count + 1
for c in players:
game = db.game.find_one({'parent_api__id':'schedule', 'id':c['game__id']})
c['date'] = game['scheduled']
print c
然後進入第二循環並迭代完全沒問題(打印出來,因爲它去一起)
這是爲什麼?我必須在每次使用其他球員時重置光標= db.player.find({'parent_api__id':'stats','game__id':{'$ in':games_list},「played」:「true」 }); ?似乎不可能如此。
感謝您提供任何幫助!
這是在Python和其他語言中使用的標準['Iterator'](https://docs.python.org/2/library/stdtypes.html#iterator-types)模式。迭代結果集兩次似乎不常見。 – Stennie 2014-08-30 11:22:03