1

我正在尝试通过从当前用户的设置中获取它们来为文档设置一些默认值,这些设置在我的快速中间件的 req.user 对象中可用。

我知道可以将 req 对象传递给中间件,但是可以将它传递给 Schema 默认函数吗?就像是:

var Comment = new Schema({
  mood:{ type: String, default: function(req) {
    return (req.user.defaults.mood);
  }},
  content: String
});
4

0 回答 0