Update mongodb and simplify the logic of mongodbPing

pull/2328/head
Louis Lam 2 years ago
parent e48a987b9c
commit 1326761a8a

14
package-lock.json generated

@ -39,7 +39,7 @@
"jsonwebtoken": "~9.0.0", "jsonwebtoken": "~9.0.0",
"jwt-decode": "~3.1.2", "jwt-decode": "~3.1.2",
"limiter": "~2.1.0", "limiter": "~2.1.0",
"mongodb": "^4.12.0", "mongodb": "~4.13.0",
"mqtt": "~4.3.7", "mqtt": "~4.3.7",
"mssql": "~8.1.4", "mssql": "~8.1.4",
"mysql2": "~2.3.3", "mysql2": "~2.3.3",
@ -13611,9 +13611,9 @@
} }
}, },
"node_modules/mongodb": { "node_modules/mongodb": {
"version": "4.12.0", "version": "4.13.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.12.0.tgz", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.13.0.tgz",
"integrity": "sha512-ssWod7DqVE4faluZESdOqYhV1BI5CQA5c31sr+zxDLJDBX9EA5VJLo8RNSItPTwxExmuGn/T6MbETQWjywNehA==", "integrity": "sha512-+taZ/bV8d1pYuHL4U+gSwkhmDrwkWbH1l4aah4YpmpscMwgFBkufIKxgP/G7m87/NUuQzc2Z75ZTI7ZOyqZLbw==",
"dependencies": { "dependencies": {
"bson": "^4.7.0", "bson": "^4.7.0",
"mongodb-connection-string-url": "^2.5.4", "mongodb-connection-string-url": "^2.5.4",
@ -28738,9 +28738,9 @@
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
}, },
"mongodb": { "mongodb": {
"version": "4.12.0", "version": "4.13.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.12.0.tgz", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.13.0.tgz",
"integrity": "sha512-ssWod7DqVE4faluZESdOqYhV1BI5CQA5c31sr+zxDLJDBX9EA5VJLo8RNSItPTwxExmuGn/T6MbETQWjywNehA==", "integrity": "sha512-+taZ/bV8d1pYuHL4U+gSwkhmDrwkWbH1l4aah4YpmpscMwgFBkufIKxgP/G7m87/NUuQzc2Z75ZTI7ZOyqZLbw==",
"requires": { "requires": {
"@aws-sdk/credential-providers": "^3.186.0", "@aws-sdk/credential-providers": "^3.186.0",
"bson": "^4.7.0", "bson": "^4.7.0",

@ -96,7 +96,7 @@
"jsonwebtoken": "~9.0.0", "jsonwebtoken": "~9.0.0",
"jwt-decode": "~3.1.2", "jwt-decode": "~3.1.2",
"limiter": "~2.1.0", "limiter": "~2.1.0",
"mongodb": "^4.12.0", "mongodb": "~4.13.0",
"mqtt": "~4.3.7", "mqtt": "~4.3.7",
"mssql": "~8.1.4", "mssql": "~8.1.4",
"mysql2": "~2.3.3", "mysql2": "~2.3.3",

@ -325,22 +325,15 @@ exports.mysqlQuery = function (connectionString, query) {
* @returns {Promise<(string[]|Object[]|Object)>} * @returns {Promise<(string[]|Object[]|Object)>}
*/ */
exports.mongodbPing = async function (connectionString) { exports.mongodbPing = async function (connectionString) {
let client; let client = await MongoClient.connect(connectionString);
let dbPing = await client.db().command({ ping: 1 });
try {
client = await MongoClient.connect(connectionString, { useNewUrlParser: true });
let db = client.db();
let dbping = await db.command({ ping: 1 });
await client.close(); await client.close();
if (dbping["ok"] === 1) {
if (dbPing["ok"] === 1) {
return "UP"; return "UP";
} else { } else {
throw Error("failed"); throw Error("failed");
} }
} catch (err) {
console.error(err);
throw Error(err);
}
}; };
/** /**

Loading…
Cancel
Save