Passing model parameters into a mongoose model

前端 未结 3 1313
走了就别回头了
走了就别回头了 2020-12-18 01:26

I have a mongoose model that has an association with a user model e.g.

var exampleSchema = mongoose.Schema({
   name: String,
   
           


        
3条回答
  •  时光说笑
    2020-12-18 02:09

    Since Node 8.3, you can also use Object Spread syntax.

    var model = new Example({ ...req.body, userId: req.user._id });
    

    Note that order matters, with later values overriding previous ones.

提交回复
热议问题