用猫鼬将响应存储在mongodb中

时间:2018-08-12 07:44:23

标签: javascript express mongoose

我将node.jsexpress一起使用,并且需要将响应存储在数据库中(MongoDBmongoose一起存储在数据库中。)

型号:

var ConnectionSchema = new mongoose.Schema({
   res:Object,
   user:{
       type: mongoose.Schema.Types.ObjectId,
       ref: "User"
   },        
});

功能进行存储:

  app.use(function(req,res,next){
    var Connection = require('./models/connection')
    Connection.create({res:res}, function(err, connection){
      if(err){
        console.log(err)
      } else {
        console.log(connection)
      }
    })  
  })

不幸的是,这导致以下错误:

cyclic dependency detected

出于测试目的,我在应用创建后立即使用了第一个中间件,因此实际上无法在我的应用中创建循环依赖关系-我相信它们带有{{1 }}。但是,有没有机会将其存储起来?

0 个答案:

没有答案