Mongoose只支持数组中的embedded式文档吗?

我在MongoDB中有一些数据,如下所示:

{ name: "Steve", location: { city: "Nowhere, IL", country: "The United States of Awesome" } } 

我使用对象来组织常见的数据结构(如位置),在Mongoose中可能很好地映射到Schema。 不幸的是,他们似乎并不真正在mongoose中工作。

如果我只是embedded一个对象,像这样:

 { name: String, location: { city: String, country: String } } 

它似乎工作,但performance出一些奇怪的行为,导致我的问题(例如instance.location.location返回location和子对象从父架构inheritance方法)。 我在Mongoose列表上启动了一个线程 ,但是没有看到任何动作。

如果我embedded一个Schema,像这样:

 { name: String, location: new Schema({ city: String, country: String }) } 

…我的应用程序无法启动( Schema不是Mongoose支持的types)。 同上

 { name: String, location: Object } 

无论如何,这不会是理想的。

我是否错过了一些东西,或者我的模式与Mongoose不一样?

我做了类似的事情:

 var Topic = new Schema({ author : ObjectId , title : String , body : String , topics : [Topic] }); 

这在我的testing中运行良好。 但是,删除arrays的导致错误。 看起来像是一个bug。

https://github.com/LearnBoost/mongoose/blob/master/lib/mongoose/schema.js#L185

转储types,我只得到string,数字,布尔,DocumentArray,数组,date,ObjectId,混合 – 这似乎是故意的,架构/ index.js看起来不像它dynamic注册新的架构types列表,所以我猜这不是一个支持的用例。

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

“embedded单个文档是不可能的,这不是一个好主意(只要使用普通的嵌套对象)”

玩笑

看起来这是一个bug ,已经在Mongoose 2.0中修复了!