This commit is contained in:
Wolfgang Hottgenroth 2018-05-14 15:24:51 +02:00
parent d14b83f3ef
commit c22b40abb7
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
2 changed files with 7 additions and 7 deletions

View File

@ -3,15 +3,15 @@
"brokerUser": "", "brokerUser": "",
"brokerPass": "", "brokerPass": "",
"brokerCa": "", "brokerCa": "",
"mongoDbUrl": "mongodb://localhost/testdb", "mongodbUrl": "mongodb://localhost/smarthome",
"verbose": false, "verbose": true,
"instances": [ "instances": [
{ {
"instanceId": "testInstance", "instanceId": "testInstance",
"collection": "testcollection", "collection": "testcollection",
"topics": [ "topic1", "topic2", "topic3" ], "topics": [ "topic1", "topic2", "topic3" ],
"encapsulate": false, "encapsulate": true,
"parsePayload": false "parsePayload": true
} }
] ]
} }

View File

@ -39,12 +39,12 @@ export default class MqttMongo extends Events.EventEmitter {
connectToDatabase() { connectToDatabase() {
this.loginfo("About to connect to database") this.loginfo("About to connect to database")
Mongo.MongoClient.connect(this.options.database) Mongo.MongoClient.connect(this.options.mongodbUrl)
.then( .then(
(tmpDbHandle: Mongo.Db) => { (tmpDbHandle: Mongo.Db) => {
this.dbHandle = tmpDbHandle this.dbHandle = tmpDbHandle
this.dbReady = true; this.dbReady = true;
this.loginfo("Database connected") this.loginfo(`Database ${this.options.mongodbUrl} connected`)
this.dbHandle.on('reconnectFailed', (err : any) => { this.logwarn(`Error on database ${err}`) }) this.dbHandle.on('reconnectFailed', (err : any) => { this.logwarn(`Error on database ${err}`) })
this.dbHandle.on('reconnect', () => { this.dbHandle.on('reconnect', () => {
this.loginfo("Reconnect on database") this.loginfo("Reconnect on database")
@ -77,7 +77,7 @@ connectToDatabase() {
.then( .then(
(r) => { (r) => {
if (this.options.verbose) { if (this.options.verbose) {
this.loginfo(`Successfully inserted into database ${JSON.stringify(msg.getMessage())}`) this.loginfo(`Successfully inserted into database ${this.options.mongodbUrl}, ${this.options.collection}: ${JSON.stringify(msg.getMessage())}`)
} }
}, },
(err) => { (err) => {