From 4da92993afdc5cd695c09c5cc423416c69bb58cd Mon Sep 17 00:00:00 2001 From: zeus Date: Wed, 9 Dec 2020 14:04:41 +0200 Subject: [PATCH] getlog --- swarmlab-app/src/run/app.js | 44 +++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 2115253..5a37df4 100755 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -317,18 +317,44 @@ if(RES.error == 'ok'){ const db = client.db('fluent'); //db.collection('log', onCollection); console.log(JSON.stringify('mongo connected')) - var stream = db.collection('logs').find({}, { - tailable: true, - awaitdata: true - }).stream(); - stream.on('data', function (doc) { - console.log(JSON.stringify(doc)) - //socket.write(JSON.stringify({'action': 'log','param': doc.log})); +db.collection('logs').find({}, {}) + .then(item => { + console.log(item) RES.error_msg = "ok" - RES.data = doc + RES.data = item + res.json(RES) + }) + .catch(err => { + console.error(err) + RES.error_msg = err + RES.data = stream res.json(RES) - }); + }) + + + + +const find = async () => { + try { + var stream = await db.collection('logs').find({}, {}) + RES.error_msg = "ok" + RES.data = stream + res.json(RES) + } catch(err => { + RES.error_msg = err + RES.data = stream + res.json(RES) + }) +} + +await find() + + + //stream.on('data', function (doc) { + // console.log(JSON.stringify(doc)) + //socket.write(JSON.stringify({'action': 'log','param': doc.log})); + //}); } }); }else{