我收到如下错误。
错误:检测到循环依赖性 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:331:34)
代码如下..
在db.connection.js
中const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/mean");
require("./hotel.model");
在hotel.schema.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const HotelSchema = new Schema({
name : {
type : String,
required : [true, "Hotel name is required"]
},
stars : {
type : Number,
min : 0,
max : 5,
default : 0
},
description : String,
services : [String]
});
mongoose.model("Hotel",HotelSchema);
在server.js
中const express = require("express");
const http = require("http");
const path = require("path");
const mongoose = require(path.join(__dirname,"server","db","db.connection"));
const routes = require("./server/routes")
const app = express();
port = 3000;
app.set("port",port);
app.use(express.static(path.join(__dirname,"dist")));
app.use("/api",routes);
app.use('*',(req,res)=>{
res.sendFile(__dirname,"dist","index.html");
});
const server = http.createServer(app);
server.listen(port,()=>console.log("listening to port : "+port));
所以当我运行“node server.js”时,我收到了开头提到的错误。
完整堆栈跟踪:
F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ mongoose \ lib \ utils.js:440 扔错了; ^
错误:检测到循环依赖性 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:331:34) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17) 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:345:18) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17) 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:345:18) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17) 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:345:18) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17) 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:345:18) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17) 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:345:18) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17) 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:345:18) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17) 在serializeObject(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:345:18) 在serializeInto(F:\ Full Stack course \ code_base \ meanhotel \ node_modules \ bson \ lib \ bson \ parser \ serializer.js:934:17)
有人可以帮我解决这个问题.. 提前谢谢。
答案 0 :(得分:3)
更新您的猫鼬,这应该可以解决您的问题。
答案 1 :(得分:0)
在hotel.schema.js文件的末尾添加此内容会有所帮助
HotelSchema.set('autoIndex', false);