Mongoose 错误:'操作详细信息. insertOne()'缓冲在10000ms后超时

xoshrz7s  于 2023-02-13  发布在  Go
关注(0)|答案(1)|浏览(262)

我在学习第一次使用nodejs和mongoDB进行设置时遇到了一个问题。
onst err =新 Mongoose 错误(消息);^
Mongoose 错误:操作详情. insertOne()缓冲超时10000ms
这是我的app.js文件数据,我得到这个错误。

const { request, response } = require('express')
const express = require('express');
const hbs = require('hbs');
const app = express();
const mongoose = require("mongoose");

const routes = require('./routes/main');
const Detail = require('./models/Detail');

// /static/css/style.css
app.use('/static', express.static("public"))
// app.use(express.static("public"))

app.use('', routes)

// Template Engine HBS 
app.set('view engine', 'hbs')
// this is the path where our all HTML files are available
app.set('views', 'views')
hbs.registerPartials('views/partials')


// MogoDB Connections
mongoose.set("strictQuery", false);
mongoose.connect("mongodb://localhost/nodejslearning", () => {
    console.log("database connected") 
    Detail.create(
        {
            brandName:"Learn NodeJS",
            brandIconUrl:"/",
            links:[
                {
                    label:"Home",
                    url:"/",
                },
                {
                    label:"Services",
                    url:"/",
                },
                
            ]
        }
    )
})

 
app.get('/', (request, response) => {
    response.send("Wow This is the data from our server")
})

app.listen(process.env.PORT | 1111, () => {
    console.log('our website server is running now')
})
    • 这是我的Detail.js文件代码**
const mongoose = require('mongoose');
const Detail = mongoose.Schema({
    brandName:String,
    brandIconUrl:String,
    navbarLinks:[
        {
            label:String,
            url:String,
        }
    ]
})

module.exports = mongoose.model("detail", Detail)
bvhaajcl

bvhaajcl1#

连接未建立,超时。请设置主机和端口,不要使用localhost

mongoose.connect("mongodb://127.0.0.1:27017/nodejslearning", () => { /*...*/}

相关问题