Skip to content

Commit

Permalink
established connection with test mongo db
Browse files Browse the repository at this point in the history
  • Loading branch information
skorphil committed Mar 4, 2024
1 parent 3b9c7e6 commit 728fbf7
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 4 deletions.
8 changes: 8 additions & 0 deletions app/api/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { dbConnect } from "../../lib/dbConnect";

export default async function handler(req, res) {
//the rest of your code here
}

await dbConnect();
// dbConnect().catch((err) => console.error("MongoDB connection error:", err));
23 changes: 23 additions & 0 deletions lib/dbConnect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use server";
import mongoose from "mongoose";
const uri = process.env.MONGO_URI;

export async function dbConnect() {
await mongoose.connect(uri, {
useNewUrlParser: true,
serverSelectionTimeoutMS: 5000,
socketTimeoutMS: 45000,
family: 4, // Use IPv4, skip trying IPv6
});
console.log("models:", mongoose.models);

console.log("Mongoose connected to MongoDB Atlas!");
const kittySchema = new mongoose.Schema({
name: String,
});
const Cat = mongoose.models.Cat || mongoose.model("Cat", kittySchema);
console.log("Cat modeled");

const fluffy = new Cat({ name: "fluffy" });
fluffy.save;
}
191 changes: 187 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@emotion/styled": "^11.11.0",
"decimal.js": "^10.4.3",
"framer-motion": "^11.0.8",
"mongoose": "^8.2.0",
"next": "14.1.1",
"numeral": "^2.0.6",
"postcss-loader": "^8.1.1",
Expand Down

0 comments on commit 728fbf7

Please sign in to comment.