Node.js 在Mongoose中声明具有相似名称的密钥
我有个新问题。我在看这个shema fnd不能用相似的名字声明一个密钥Node.js 在Mongoose中声明具有相似名称的密钥,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我有个新问题。我在看这个shema fnd不能用相似的名字声明一个密钥 exports = module.exports = function(app, mongoose) { var accountSchema = new mongoose.Schema({ user: { id: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, name: { type: String, default: ''
exports = module.exports = function(app, mongoose) {
var accountSchema = new mongoose.Schema({
user: {
id: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
name: { type: String, default: '' }
},
isVerified: { type: String, default: '' },
verificationToken: { type: String, default: '' },
name: {
first: { type: String, default: '' },
middle: { type: String, default: '' },
last: { type: String, default: '' },
full: { type: String, default: '' }
},
company: { type: String, default: '' },
phone: { type: String, default: '' },
zip: { type: String, default: '' },
status: {
id: { type: String, ref: 'Status' },
name: { type: String, default: '' },
userCreated: {
id: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
name: { type: String, default: '' },
time: { type: Date, default: Date.now }
}
},
statusLog: [mongoose.modelSchemas.StatusLog],
notes: [mongoose.modelSchemas.Note],
userCreated: {
id: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
name: { type: String, default: '' },
time: { type: Date, default: Date.now }
},
search: [String]
假设我这里有一个
user.name
和status.name
键,name
键本身有name.first
<代码>名称.完整属性。猫鼬如何知道使用哪个名称
?声明键名的最佳实践是什么?它会导致什么问题 您似乎对JavaScript对象和键的工作方式缺乏基本的了解。account.name与account.user.name和account.status.name不同。使用相同的属性名不是问题,因为它们是完全不同对象的属性。@AJ Funk是的,基本上我明白了。但是在这里,我们还有user.name
和带有第一、中间、最后和完整子键的独立name
,它们必须是同一个对象的属性,但是单独声明,而不是声明为子属性。