From 32e1f821b928fdd57d0f817d3f8590c39ac64321 Mon Sep 17 00:00:00 2001 From: zeus Date: Tue, 24 Nov 2020 17:20:55 +0200 Subject: [PATCH] mongo tail --- swarmlab-app/src/run/app.js | 42 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 7d00378..091de65 100755 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -387,16 +387,40 @@ function onCollection(err, collection) { // db.collection('log', onCollection); //} -//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/?replicaSet=rs1" -var mongourl = "mongodb://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/?replicaSet=rs1" -//MongoClient.connect(mongourl, options).then((client) => { -//MongoClient.connect("mongodb://member1,member2,member3/database", function(err,db) { -//}) +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 mongolab_uri = "mongodb://:@:,:/?replicaSet="; var mongooptions = { - auth.user:"playgrounduser", - auth.password:'efvvnuioervefSDFSGYGHRDFVsdfergvssppiiedifhwincvinviw_dbfjbsifbsdkjfswuunscfudfgbbfvibqefwrvnine' + server: { + socketOptions: { + autoReconnect: true, + keepAlive: 1, + connectTimeoutMS: 30000, + socketTimeoutMS: 0 + } + }, + replSet: { + socketOptions: { + keepAlive: 1, + connectTimeoutMS: 30000, + socketTimeoutMS: 0 + } + } } -MongoClient.connect(mongourl,mongooptions).then((client) => { +MongoClient.connect(mongourl, mongooptions, function(err, db){ + if(err){ + console.log(err); + } else { + db.collections(function(err, collections) { + collections.forEach(function(coll) { + console.log(coll.s.name); + }); + }); + } +}); + +//MongoClient.connect(mongourl,mongooptions).then((client) => { +/* +MongoClient.connect(mongourl).then((client) => { const db = client.db('fluent'); db.collection('log', onCollection); // do database things @@ -404,7 +428,7 @@ MongoClient.connect(mongourl,mongooptions).then((client) => { console.log("connect_error_mongo " +JSON.stringify(error)) // handle connection errors }); - +*/ io.on('connection', s => { console.error('socket connection');