【发布时间】:2015-09-21 22:25:00
【问题描述】:
我在 mongodb 中创建了一个非常嵌套的模式。看起来像这样
{
"_id": ObjectID("559690ec34c506cea4be1775"),
"cities": [
{
"val": "something",
"pincode": [
{
"val": "something",
"people": [
{
"val": "something",
"frnds": [
{
"val": "something1",
"frndaddress": [
{
"val": "something2"
}
]
}
]
}
]
}
]
}
]
}
此文档已正确插入到 mongodb 中,但我不知道如何在 mongoose 上转换它
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// create a all city list, without id
var allCitySchema = new Schema({
cities: [{
val:{ type: String },
pincode:[{
val:{ type: String },
people:[{
val:{ type: String },
frnds:[{
val:{ type: String },
frndaddress:[{
val:{ type: String },
}]
}]
}]
}]
}]
}, {collection: 'allcities'});
var allcities = mongoose.model('allcities', allCitySchema);
module.exports = allcities;
我是节点和 mongodb 的新手,我在上面创建的架构我什至不知道它是否正确。
【问题讨论】:
-
its seems its not working你能详细说明一下吗? -
当我尝试插入数据时,它的显示验证失败