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"
const OPTS = {
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 = {
useNewUrlParser: true,
useUnifiedTopology: true
};
//var mongolab_uri = "mongodb://<dbUser>:<dbPassword>@<host1>:<port1>,<host2>:<port2>/<dbName>?replicaSet=<replicaSetName>";
var mongooptions = {
};
//var mongolab_uri = "mongodb://<dbUser>:<dbPassword>@<host1>:<port1>,<host2>:<port2>/<dbName>?replicaSet=<replicaSetName>";
var mongooptions = {
autoReconnect: true,
keepAlive: 1,
connectTimeoutMS: 30000,
socketTimeoutMS: 0
}
MongoClient.connect(mongourl, OPTS, function(err, client){
}
MongoClient.connect(mongourl, OPTS, function(err, client){
if(err){
console.log(err);
} else {
const db = client.db('fluent');
db.collection('logs', onCollection);
var stream = db.collection('logs').find({}, {
db.collection('logs', onCollection);
/*
var stream = db.collection('logs').find({}, {
tailable: true,
awaitdata: true
/* other options */
}).stream();
//other options
}).stream();
stream.on('data', function (doc) {
stream.on('data', function (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