4

i have a model like this :

Mongoose Schema

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

  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 !');
  }
});

so i am trying to achieve a post function that does not allow duplicates and so i found the {upsert:true} in an updateOne. this worked perfectly until i had to make a call that filters out some data. so i get a batch of data and i only want to get the data that fits in the model.

but because not everything is defined in the model i get a StrictMode error. and when i disable the strictMode i get all the data that wasnt even defined in the model.

evidence of this occurrence

enter image description here

as you can see here isCommentable, islikable and isliked has been added without it being defined. and i know this is because i put {strict:false} but if i do not add this is, no data gets added and i get the following error:

{ StrictModeError: Path "updateType" is not in schema, strict mode is true, and upsert is true.

so i was wondering how can i fix this without adding anything to my model or using the {strict:false}.

Hopefully anyone can help me with this, anymore info that is necessary: name it and i will edit it in.

Lars Hendriks
  • 803
  • 2
  • 16

0 Answers0