4

我有一个这样的模型:

猫鼬模式

var LinkedinUpdateSchema = new mongoose.Schema({
  likes:{values:[PersonSchema],
    _total: Number},
  numLikes: Number,
  timestamp: Number,
  updateComments:{
    values:[CommentSchema],
    _total: Number
  },
  updateContent:{
    companyStatusUpdate:{
      share:{
        comment: String,
        timestamp: Number
      }
    }
  },
});

路由器

  router.post('/:type',function(req,res,next){
  if(cutFilename.includes(req.params.type)){
    var object = require('./models/'+req.params.type);
    object.UpdateOne(req.body,req.body,{upsert:true,strict:false},function(err,object){
      if(err) console.log(err)
      res.json(object);
    })
  }else{
    res.json('error: type: '+ req.params.type + 'not found !');
  }
});

所以我试图实现一个不允许重复的发布功能,所以我在 updateOne 中找到了 {upsert:true}。这工作得很好,直到我不得不拨打电话过滤掉一些数据。所以我得到了一批数据,我只想得到适合模型的数据。

但因为并非所有内容都在模型中定义,所以我收到 StrictMode 错误。当我禁用严格模式时,我得到了模型中甚至没有定义的所有数据。

这一事件的证据

在此处输入图像描述

正如您在此处看到的那样,isCommentable、islikeable 和 isliked 已被添加但未定义。我知道这是因为我放了 {strict:false} 但如果我不添加它,则不会添加任何数据,并且我收到以下错误:

{ StrictModeError:路径“updateType”不在模式中,严格模式是true,并且 upsert 是true

所以我想知道如何在不向模型添加任何内容或使用 {strict:false} 的情况下解决此问题。

希望任何人都可以帮助我,更多必要的信息:命名它,我会编辑它。

4

0 回答 0