Ich bin eine Liste looping und innerhalb dieser Schleife bin ich einige Dokumente loopen, die von mongodb abgerufen werden. Aber in der Ausgabekonsole kann ich nur eine Iteration sehen. Aber die äußere Schleife funktioniert gut. Wenn ich debugge, geht es in die äußere Schleife, aber nicht in die innere Schleife. Bitte hilf mir.Python für jede Schleife funktioniert nicht
client = MongoClient('mongodb://localhost:27017/')
db = client['mydb']
documents = icps_db.user.find({})
name_set = ['john', 'marshal', 'ann' ...]
for name in name_set:
print(name)
for idx, document in enumerate(documents):
print (documents)
if name in document["filtered_words"]:
print ("Found " + name)
else:
print (name + " not found in document ")
Ausgabe In der zweiten Iteration es nicht Linie nicht erreicht: print (str (idx)).
john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
john
marshal
marshal
Sind Sie sicher, dass 'Dateien' nicht leer ist? Vielleicht drucken Sie diese Sammlung zuerst aus. –
'Dokumente' ist wahrscheinlich leer. – kazemakase
Dokumente sind definitiv leer – Bodao