log command

This commit is contained in:
Primakov Alexandr Alexandrovich 2024-08-27 14:23:40 +03:00
parent 69f48b83c4
commit 14035266e5

View File

@ -28,14 +28,23 @@ const mongoDBConnect = async () => {
console.error(error)
}
}
console.log('try connect')
mongoDBConnect().then(async (client) => {
console.log('Connected to MongoDB')
try {
const db = await client.db(process.env.DB_NAME)
const collection = await db.collection(process.env.COLLECTION_NAME)
const answer = await collection[process.env.COMMAND](JSON.parse(process.env.ARGUMENT))
console.log('command', process.env.COMMAND)
console.log('argument', process.env.ARGUMENT, process.env.ARGUMENT.replace("ISODate()", `${new Date().toISOString()}`))
const answer = await collection[process.env.COMMAND](JSON.parse(process.env.ARGUMENT.replaceAll("ISODate()", `${new Date().toISOString()}`)))
await client.close();
return answer.ops?.[0] ?? answer
} catch (error) {
await client.close();
}
})
.then(console.log)
.catch(console.error)