user3504250 user3504250 - 1 month ago 13
Python Question

TypeError: unsupported operand type(s) for +: 'Cursor' and 'Cursor'

I want to be able to store two collections in variable to be able to view and sort through them. However, I seem to be getting the error above.
My code is in python and look like this:

from pymongo import MongoClient

db = MongoClient('10.39.165.193', 27017)['mean-dev']
cursor1 = db.Build_Progress.find()
cursor2 = db.build_lookup.find()
joincursors = cursor1+ cursor2

for document in cook:
print(document)

Answer

You need to chain the two cursors like this:

from itertools import chain

for document in chain(cursor1, cursor2):
    print(document)