I have an operation kinda like so:
const results = Promise.all([
myColl1.find(query1).sort(sort).limit(limit).toArray(),
myColl2.find(query2).sort(sort).limit(limit).toArray(),
]);
However, it seems the results are completely unexpected. After looking what might possibly going on, the documentation states:
Warning: Because asynchronous calls directly modify the cursor, executing asynchronous calls on a single cursor simultaneously can also cause undefined behavior. Always wait for the previous asynchronous operation to complete before running another.
The "single cursor" part seems to imply it might be possible to do this with two separate cursors? I'm actually not too sure of the technical details but, wouldn't the fact that myColl1 != myColl2 mean they're separate cursors? I've actually been considering joining the collections, so if they were the same, would it be possible to use separate cursors? Any help is appreciated.
Do you use await? I made some changes to what you originally posted:
const [res1, res2] = await Promise.all([
await myColl1.find(query1).sort(sort).limit(limit).toArray(),
await myColl2.find(query2).sort(sort).limit(limit).toArray()
]);
I hope this helps ✌🏼