From c1479a755276f44306836d6d1cd62b9abfceefaf Mon Sep 17 00:00:00 2001 From: zeus Date: Tue, 24 Nov 2020 19:59:44 +0200 Subject: [PATCH] mongo tail --- swarmlab-app/src/run/app.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 9f584c6..365b71c 100755 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -265,13 +265,14 @@ MongoClient.connect(mongourl, OPTS, function(err, client){ } else { const db = client.db('fluent'); //db.collection('log', onCollection); + console.log(JSON.stringify('mongo connected')) var stream = db.collection('log').find({}, { tailable: true, awaitdata: true /* other options */ }).stream(); -db.on('data', function (doc) { +stream.on('data', function (doc) { console.log(JSON.stringify(doc)) //socket.write(JSON.stringify({'action': 'log','param': doc.log})); }); @@ -409,12 +410,8 @@ function onCollection(err, collection) { itemsProcessed++; }); - var cursor1 = collection.find({},options); - console.log(JSON.stringify(cursor1.value)) setInterval(function () { - var cursor2 = collection.find({},options); - console.log(JSON.stringify(cursor2.value)) console.log('itemsProcessed', itemsProcessed); }, 1000); } @@ -437,14 +434,14 @@ MongoClient.connect(mongourl, OPTS, function(err, client){ console.log(err); } else { const db = client.db('fluent'); - //db.collection('log', onCollection); - var stream = db.collection('log').find({}, { +db.collection('log', onCollection); +var stream = db.collection('log').find({}, { tailable: true, awaitdata: true /* other options */ }).stream(); -db.on('data', function (doc) { +stream.on('data', function (doc) { console.log(JSON.stringify(doc)) //socket.write(JSON.stringify({'action': 'log','param': doc.log})); });