Browse Source

mongo tail

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

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

@ -419,41 +419,36 @@ function onCollection(err, collection) {
} }
var mongourl = "mongodb://playgrounduser:efvvnuioervefSDFSGYGHRDFVsdfergvssppiiedifhwincvinviw_dbfjbsifbsdkjfswuunscfudfgbbfvibqefwrvnine@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1" var mongourl = "mongodb://playgrounduser:efvvnuioervefSDFSGYGHRDFVsdfergvssppiiedifhwincvinviw_dbfjbsifbsdkjfswuunscfudfgbbfvibqefwrvnine@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1"
const OPTS = { const OPTS = {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true useUnifiedTopology: true
}; };
//var mongolab_uri = "mongodb://<dbUser>:<dbPassword>@<host1>:<port1>,<host2>:<port2>/<dbName>?replicaSet=<replicaSetName>"; //var mongolab_uri = "mongodb://<dbUser>:<dbPassword>@<host1>:<port1>,<host2>:<port2>/<dbName>?replicaSet=<replicaSetName>";
var mongooptions = { var mongooptions = {
autoReconnect: true, autoReconnect: true,
keepAlive: 1, keepAlive: 1,
connectTimeoutMS: 30000, connectTimeoutMS: 30000,
socketTimeoutMS: 0 socketTimeoutMS: 0
} }
MongoClient.connect(mongourl, OPTS, function(err, client){ MongoClient.connect(mongourl, OPTS, function(err, client){
if(err){ if(err){
console.log(err); console.log(err);
} else { } else {
const db = client.db('fluent'); const db = client.db('fluent');
db.collection('logs', onCollection); db.collection('logs', onCollection);
var stream = db.collection('logs').find({}, { /*
tailable: true, var stream = db.collection('logs').find({}, {
awaitdata: true tailable: true,
/* other options */ awaitdata: true
}).stream(); //other options
}).stream();
stream.on('data', function (doc) {
console.log('doc ' + JSON.stringify(doc)) stream.on('data', function (doc) {
//socket.write(JSON.stringify({'action': 'log','param': doc.log})); console.log('doc ' + JSON.stringify(doc))
});
/*
db.collection(function(err, collections) {
collections.forEach(function(coll) {
console.log(coll.s.name);
});
}); });
*/ */
} }
}); });

Loading…
Cancel
Save