mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-03 03:56:18 -04:00
Update mongodb and simplify the logic of mongodbPing
This commit is contained in:
parent
e48a987b9c
commit
1326761a8a
3 changed files with 15 additions and 22 deletions
|
@ -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");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue