我有一个“套接字”模型的模式,当我尝试在猫鼬中保存任何创建的套接字对象时,它给我一个模糊的错误,Error: cyclic dependency detected仅标记node_modules,而不标记我的任何文件。架构代码如下。我保存套接字对象的方式也如下。如果可能的话请指出错误。
套接字.js 文件
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const SocketSchema = new mongoose.Schema({
_id: Schema.Types.ObjectId,
socket_object: Schema.Types.Mixed,
socket_id: Schema.Types.Mixed,
// other model links
room_link: { type: Schema.Types.ObjectId, ref: 'Room' },
})
SocketSchema.pre('save', function(next) {
this.socket_id = this.socket_object.id;
next();
});
// SocketSchema.set('autoIndex', false);
mongoose.model('Socket', SocketSchema);
Run Code Online (Sandbox Code Playgroud)
我如何保存套接字对象:
let newSocket = new Socket({
_id: new mongoose.Types.ObjectId(),
socket_object: socket,
});
console.log('-----------------NEW SOCKET---------------')
console.log(newSocket)
newSocket.save(function(err, newSocket){
if (err) {
console.log('--------------------LOG SOCKET NOT SAVED------------------------')
return console.log(err)
}
}) …Run Code Online (Sandbox Code Playgroud)