Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My problem is while the loop is never terminated.

This my changeStream object:

const changeStreamIterator = userModel.User.collection.watch(filter, {
     fullDocument: "default",
     startAtOperationTime: startAtOperationTime,
     readPreference: "primary",
});

Read results with this code:

   while (await changeStreamIterator.hasNext()) {
               
           let change = await changeStreamIterator.next();

           console.log("change");
   }
.
.
.

after the above code, my code not resumed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
481 views
Welcome To Ask or Share your Answers For Others

1 Answer

A change stream is infinitely long. If you make a loop iterating it, this loop will be an infinite one.

Use patterns available in node to do other work concurrently.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...