mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
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]>
20 lines
589 B
TypeScript
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;
|
|
}
|
|
}
|