Browse Source

mongo tail

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

33
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({}, { /*
var stream = db.collection('logs').find({}, {
tailable: true, tailable: true,
awaitdata: true awaitdata: true
/* other options */ //other options
}).stream(); }).stream();
stream.on('data', function (doc) { stream.on('data', function (doc) {
console.log('doc ' + JSON.stringify(doc)) console.log('doc ' + JSON.stringify(doc))
//socket.write(JSON.stringify({'action': 'log','param': doc.log}));
});
/*
db.collection(function(err, collections) {
collections.forEach(function(coll) {
console.log(coll.s.name);
});
}); });
*/ */
} }
}); });

Loading…
Cancel
Save