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

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

javascript - Mongoose change stream "hasNext()" behavior always is true

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.


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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...