我在MongoDB的一些數據,看起來像這樣:Mongoose是否僅支持數組中的嵌入式文檔?
{
name: "Steve",
location: {
city: "Nowhere, IL",
country: "The United States of Awesome"
}
}
我使用對象來組織常用的數據結構(如位置),這在貓鼬會很好地映射到架構。不幸的是,他們似乎並沒有真正在Mongoose中工作。
如果我只是嵌入的對象,像這樣:
{
name: String,
location: {
city: String,
country: String
}
}
這似乎是工作,但表現出了導致爲我如instance.location.location
返回location
,和子對象繼承方法從父模式問題(一些奇怪的行爲)。我在貓鼬列表上輸入started a thread,但它沒有看到任何操作。
如果我嵌入模式,就像這樣:
{
name: String,
location: new Schema({
city: String,
country: String
})
}
...我的應用程序不啓動(Schema
是不是貓鼬支持的類型)。同上
{
name: String,
location: Object
}
......不管怎樣都不是理想的。
我錯過了什麼,或者我的模式與Mongoose不一樣嗎?
查看文檔 - > http://mongoosejs.com/docs/embedded-documents.html。 – 2011-05-30 06:58:19
@Andrew我有。你在向我展示什麼?我注意到它說:*「嵌入式文檔是具有自己的模式的文檔,它們是其他文檔的一部分(作爲數組中的項目)。」*這是否意味着Mongoose不支持像我這樣的模式? – s4y 2011-05-30 15:47:17