Browse Source

getlog

master
zeus 4 years ago
parent
commit
4da92993af
  1. 44
      swarmlab-app/src/run/app.js

44
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{

Loading…
Cancel
Save