Files
f33097c174 with-mongodb update to add both App and Pages Router examples (#68461)
Updated all dependencies and added an app route to demonstrate both
pages an app directories.

---------

Co-authored-by: Delba de Oliveira <[email protected]>
Co-authored-by: Sam Ko <[email protected]>
2024-08-02 13:12:19 -07:00

20 lines
589 B
TypeScript

"use server";
import client from "@/lib/mongodb";
export async function testDatabaseConnection() {
let isConnected = false;
try {
const mongoClient = await client.connect();
// Send a ping to confirm a successful connection
await mongoClient.db("admin").command({ ping: 1 });
console.log(
"Pinged your deployment. You successfully connected to MongoDB!",
); // because this is a server action, the console.log will be outputted to your terminal not in the browser
return !isConnected;
} catch (e) {
console.error(e);
return isConnected;
}
}