cgserver 13.2.1 → 13.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -23,11 +23,15 @@ class MongoBaseService {
|
|
|
23
23
|
if (this._model) {
|
|
24
24
|
return this._model;
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
26
|
+
if (!this.mongo) {
|
|
27
|
+
Log_1.gLog.error("MongoDB connection is not established, please check the connection settings.");
|
|
28
|
+
throw new Error("MongoDB connection is not established");
|
|
29
|
+
}
|
|
30
|
+
if (!this.mongo.connected) {
|
|
27
31
|
Log_1.gLog.error("MongoDB connection is not ready, please check the connection settings. Current state: " + mongoose_1.default.connection.readyState);
|
|
28
32
|
throw new Error("MongoDB connection is not ready");
|
|
29
33
|
}
|
|
30
|
-
let db =
|
|
34
|
+
let db = this.mongo.connection.db;
|
|
31
35
|
if (!db || db.databaseName == "test") {
|
|
32
36
|
Log_1.gLog.error("MongoDB connection is not valid, please check the connection settings.");
|
|
33
37
|
throw new Error("MongoDB connection is not valid");
|
|
@@ -122,6 +122,9 @@ class MongoExt {
|
|
|
122
122
|
get connection() {
|
|
123
123
|
return this._connection;
|
|
124
124
|
}
|
|
125
|
+
get connected() {
|
|
126
|
+
return this._connection && this._connection.readyState === 1;
|
|
127
|
+
}
|
|
125
128
|
constructor() {
|
|
126
129
|
}
|
|
127
130
|
async init(cfg) {
|
|
@@ -135,13 +138,14 @@ class MongoExt {
|
|
|
135
138
|
this._inited = true;
|
|
136
139
|
Log_1.gLog.info("mongo config=" + JSON.stringify(this._mongocfg));
|
|
137
140
|
this._mongocfg.options.dbName = this._mongocfg.database;
|
|
138
|
-
this._connection =
|
|
141
|
+
this._connection = mongoose_2.default.createConnection("mongodb://" + this._mongocfg.host + ":" + this._mongocfg.port, this._mongocfg.options);
|
|
142
|
+
this._connection = this._connection.useDb(this._mongocfg.database);
|
|
139
143
|
this._connection.on("open", this.onOpen.bind(this));
|
|
140
144
|
this._connection.on("close", this.onClose.bind(this));
|
|
141
|
-
this._connection.useDb(this._mongocfg.database);
|
|
142
145
|
this._connection.on("connectionCreated", this.onConnect.bind(this));
|
|
143
146
|
this._connection.on("connectionClosed", this.onDisconnect.bind(this));
|
|
144
|
-
|
|
147
|
+
await this._connection.asPromise();
|
|
148
|
+
console.log("mongo connect success! db=" + this._connection.name);
|
|
145
149
|
return true;
|
|
146
150
|
}
|
|
147
151
|
onConnect() {
|