我在 MongoDB 中有一些数据,如下所示:
{
name: "Steve",
location: {
city: "Nowhere, IL",
country: "The United States of Awesome"
}
}
我正在使用对象来组织常见的数据结构(如位置),在 Mongoose 中可能很好地映射到模式。不幸的是,它们似乎并没有真正在 Mongoose 中工作。
如果我只是嵌入一个对象,像这样:
{
name: String,
location: {
city: String,
country: String
}
}
它似乎工作,但表现出一些奇怪的行为,导致我的问题(例如instance.location.location
返回location
,和子对象从父模式继承方法)。我在 Mongoose 列表上启动了一个线程,但它没有看到任何动作。
如果我嵌入一个模式,像这样:
{
name: String,
location: new Schema({
city: String,
country: String
})
}
…我的应用程序没有启动(Schema
不是 Mongoose 支持的类型)。同上
{
name: String,
location: Object
}
…无论如何,这并不理想。
我是否遗漏了某些东西,或者我的模式与 Mongoose 不兼容?