Update mongodb and simplify the logic of mongodbPing

This commit is contained in:
Louis Lam 2023-01-15 01:36:49 +08:00
parent e48a987b9c
commit 1326761a8a
3 changed files with 15 additions and 22 deletions

14
package-lock.json generated
View file

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

View file

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

View file

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