Browse Source

mongo tail

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

11
swarmlab-app/src/run/app.js

@ -265,13 +265,14 @@ MongoClient.connect(mongourl, OPTS, function(err, client){
} else { } else {
const db = client.db('fluent'); const db = client.db('fluent');
//db.collection('log', onCollection); //db.collection('log', onCollection);
console.log(JSON.stringify('mongo connected'))
var stream = db.collection('log').find({}, { var stream = db.collection('log').find({}, {
tailable: true, tailable: true,
awaitdata: true awaitdata: true
/* other options */ /* other options */
}).stream(); }).stream();
db.on('data', function (doc) { stream.on('data', function (doc) {
console.log(JSON.stringify(doc)) console.log(JSON.stringify(doc))
//socket.write(JSON.stringify({'action': 'log','param': doc.log})); //socket.write(JSON.stringify({'action': 'log','param': doc.log}));
}); });
@ -409,12 +410,8 @@ function onCollection(err, collection) {
itemsProcessed++; itemsProcessed++;
}); });
var cursor1 = collection.find({},options);
console.log(JSON.stringify(cursor1.value))
setInterval(function () { setInterval(function () {
var cursor2 = collection.find({},options);
console.log(JSON.stringify(cursor2.value))
console.log('itemsProcessed', itemsProcessed); console.log('itemsProcessed', itemsProcessed);
}, 1000); }, 1000);
} }
@ -437,14 +434,14 @@ MongoClient.connect(mongourl, OPTS, function(err, client){
console.log(err); console.log(err);
} else { } else {
const db = client.db('fluent'); const db = client.db('fluent');
//db.collection('log', onCollection); db.collection('log', onCollection);
var stream = db.collection('log').find({}, { var stream = db.collection('log').find({}, {
tailable: true, tailable: true,
awaitdata: true awaitdata: true
/* other options */ /* other options */
}).stream(); }).stream();
db.on('data', function (doc) { stream.on('data', function (doc) {
console.log(JSON.stringify(doc)) console.log(JSON.stringify(doc))
//socket.write(JSON.stringify({'action': 'log','param': doc.log})); //socket.write(JSON.stringify({'action': 'log','param': doc.log}));
}); });

Loading…
Cancel
Save