以下是我项目中一个用户配置文件的架构。
var agencyProfile = mongoose.Schema({
name: {
type: String
},
user: {
type: mongoose.Schema.ObjectId,
ref: "users"
}
})
我想知道这两个导出的架构有什么区别?
module.exports = mongoose.model('agencyProfile', agencyProfile);
vs
module.exports = mongoose.model('agencyProfile', agencyProfile, "agencyProfile");
答案 0 :(得分:1)
第三个参数基本上允许您将集合名称(默认情况下从模型名称推断)更改为其他名称。来自documentation:
<块引用>当没有传递集合参数时,Mongoose 使用模型名称。 如果您不喜欢这种行为,请传递集合名称,使用 mongoose.pluralize(),或设置您的架构集合名称选项。
就您而言,它没有任何区别,因为集合名称与模型名称 agencyProfile
匹配。