bug in "cursor.forEach" method

Carla Barazarte shared this problem 5 years ago
Solved

Hi,

I've tried version 5.0.0 and 5.0.1 of the app and I have some problems executing scripts that runs perfectly in version 4.7.4.

Particularly I have two collections Users and Commune and I have the following simple script:

db.User.find().limit(2).forEach((it)=> {

var commune = db.Commune.findOne();

print(commune);

});

When I run this in 4.7.4 it displays as a result two communes objects which is fine, but when I run this in 5.0.0 or 5.0.1 it keeps loading and loading without a result.

I figured out that this error has to be with having a find inside a forEach because when I run db.Commune.findOne(); indepently it works fine.


Thanks,

Carla

Replies (2)

photo
1

Thank you for your bug report. We will fix it in the next build.

As a workaround solution, please use "toArray()" to get the results first.

db.User.find().limit(2).toArray().forEach((it)=> {
   var commune = db.Commune.findOne();
   print(commune);
});

photo
1

Fixed in 5.0.3

Leave a Comment
 
Attach a file