Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在Mongoose中声明具有相似名称的密钥_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js 在Mongoose中声明具有相似名称的密钥

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: ''

我有个新问题。我在看这个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: '' }
    },
     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
,它们必须是同一个对象的属性,但是单独声明,而不是声明为子属性。