Search code examples
tornado-motor

Joining Cursors in Motor


Is there a way I can concat or join Motor cursors for iteration?

E.g.

cursor1 = xxx.find({"field1":field1})
cursor2 = yyy.find({"field1":field1})

# how can I join cursor1 and cursor2 together
#cursor = cursor1+ cursor2

while (yield cursor.fetch_next):         
   doc = cursor.next_object()
   print(doc)

Solution

  • No, there's no such feature in Motor.

    Once PEP 525 is implemented in Python 3.6 you'll have "async generators" that will provide a convenient way for you to write a cursor-joining function yourself. Meanwhile, just iterate the first cursor, then iterate the second cursor.