-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
established connection with test mongo db
- Loading branch information
Showing
4 changed files
with
219 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters