#Mongoose Connection Error NextJS

2 messages · Page 1 of 1 (latest)

ionic bay
#

Code
connect-mongoose.js

import mongoose from "mongoose"
const connection = {
  status: 0
}
export default async function mongoConnect() {
  try {
    console.info("Establishing Database Connection...")
    if (connection.status > 0) {
      console.info("Database Already Connected.")
      return true
    }
    const database = await mongoose.connect(process.env.DB_STRING, {
      dbName: "SF",
      autoIndex: false,
      connectTimeoutMS: 6000
    })
    connection.status = database.connections[0].readyState
    console.log("Database Connected Successfully...")
    return true
  } catch (error) {
    console.error("Error While Establishing Connection With Database.", error)
    return false
  }
}

Error:

✓ Compiled /api/blogs in 481ms (159 modules)
Establishing Database Connection...
Error While Establishing Connection With Database. [TypeError: mongoose__WEBPACK_IMPORTED_MODULE_0___default(...).connect is not a function]
[TypeError: _utils_models_blogs_model__WEBPACK_IMPORTED_MODULE_1__.Blogs.find is not a function]
vital flaxBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)