Browse Source

mongo tail

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

13
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}));
});

Loading…
Cancel
Save