我已创建以下 集合架构 ,并且已passed
验证:
db.createCollection("Settings",
{ validator: { $or:
[
{cID:{ $type: "int" } },
{sID : { $type: "int" } },
{default :
[
{default1:
{
name : { $type: "string" },
priority : { $type: "string" },
autoMoveToCompleted : { $type: "string" },
notifyInAdvance : { $type: "string" }
}
},
{default2 :
{
name : { $type: "string" },
priority : { $type: "string" },
autoMoveToCompleted : { $type: "string" }
}
}
]
},
{applied: [
{applied1:
{ name : { $type: "string" },
priority : { $type: "string" },
autoMoveToCompleted : { $type: "string" },
notifyInAdvance : { $type: "string" }
}
},
{applied2 :
{
name : { $type: "string" },
priority : { $type: "string" },
autoMoveToCompleted : { $type: "string" }
}
}
]}
]
}
}
)
但是,我无法为上面的模式生成有效的insert
语句,因为它涉及数组。我试图在谷歌中找到解决方案,但找不到与准备类似于上述架构的插入语句相关的任何内容。
请帮助为一个mongo文档生成此架构的insert
语句,以便在mongo shell上运行插入查询。
答案 0 :(得分:0)
我只能建议更改验证架构,如:
db.createCollection("Settings",
{ validator: { $or:
[
{cID:{ $type: "int" } },
{sID : { $type: "int" } },
{"default.default1.name" : { $type: "string" },
"default.default1.priority" : { $type: "string" },
"default.default1.autoMoveToCompleted" : { $type: "string" },
"default.default1.notifyInAdvance" : { $type: "string" },
"default.default2.name" : { $type: "string" },
"default.default2.priority" : { $type: "string" },
"default.default2.autoMoveToCompleted" : { $type: "string" }
}
]
}
}
)
必须有效