当定义一个字段两次时,Mongoose抛出`Field不在模式错误中

我正在使用Node v0.10.31和mongoose@3.8.22。

我想我遇到了一个特定的事情发生时出现的错误。 这个bug的影响阻止了我在同一个模式上有一个字段“name”和“father.name.full”。

这是我如何定义我的模式:

'use strict'; var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/myapp'); var PersonSchema = new mongoose.Schema({ name: { type: mongoose.Schema.Types.ObjectId, ref: 'Name', // if this is commented out, no errors required: false, default: null, }, father: { name: { full: String } // if this is `name: String`, no errors } }, { strict: 'throw' // if this is commented out, no errors }); var Person = mongoose.model('Person', PersonSchema); 

这是我如何创build文档:

 var object2save = { name: mongoose.Types.ObjectId(), father: { name: { full: 'father full name' } } } var doc = new Person(object2save); // this throws the error 

错误和堆栈跟踪是

 Error: Field `name` is not in schema. at model.Document.set (/PATH/node_modules/mongoose/lib/document.js:469:19) at model.Document.set (/PATH/node_modules/mongoose/lib/document.js:464:16) at model.Document (/PATH/node_modules/mongoose/lib/document.js:60:10) at model.Model (/PATH/node_modules/mongoose/lib/model.js:43:12) at new model (/PATH/node_modules/mongoose/lib/model.js:2535:11) at Object.<anonymous> (/PATH/Desktop/node/test-mongoose/path-type-mismatch.js:43:11) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) 

这实际上是一个错误,或者它是一个function? 如果它是一个function,那么它似乎是对模式devise的限制。 我打算在Mongoose的GitHub上创build一个问题,但我想我应该先问Stack Overflow以确保:-)

这个问题似乎是Mongoose中的一个错误。 这个问题是固定的,将在Mongoose 3.8.24发布,根据这个链接:

https://github.com/LearnBoost/mongoose/issues/2665