Relative Content

Tag Archive for node.jsmongodbmongoosedatabase-cursornode-worker-threads

Mongoose cursor times out after a couple of hours even though noCursorTimeout flag is set

export const cacheRecommendations = async () => { const userCursor = UserModel.find({}) .cursor() .addCursorFlag(“noCursorTimeout”, true); let counter = 0; for await (const user of userCursor) { console.log(“counter”, counter); counter++; await calculateRecommendationsWithTensorflow(user._id); } }; This code iterates over every user in the database. The calculations from calculateRecommendationsWithTensorflow take a couple of minutes per user to complete. […]