我有如下文件。这里peoples
包含指向用户集合的 ObjectId 数组。和contribution
字段包含的子文档数量为peoples
场地。长度是可变的,就像某个组有 2 个 ObjectId 一样people
then contribution
将有2个子文档。我需要为此创建 mongoDb 架构,请告诉我此架构。
{
name: "person name",
_id: ObjectId(""),
creater: ObjectId("1"), //referencing to user collection
peoples: [ObjectId("1"), ObjectId("2"),...upto n], //all referencing to user table
contribution: {
ObjectId("1"):{
paid: 1200,
due: 1000,
prevDue: 200,
Advance: 0
},
ObjectId("2"):{
paid: 1200,
due: 1000,
prevDue: 200,
Advance: 0
},
//upto end of lists in peoples array
},
estimated: 30000,
collected: 15379,
left: 14721
}
您只需要在 main 中引用嵌套架构schema
。例如:
let user = new Schema({
name: String
})
let schema = new Schema({
followers: [user]
})
In the followers
现场schema
,您刚刚引用了user
架构。每当进行这种引用时,nested schema
注入参考点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)