我有这个文档结构,属性“名称”在所有文档中必须是唯一的,如上所示:
{
"_id" : ObjectId("56686341d6389c004c689d5d"),
"Bosses" : {
"B1" : {
"_id" : NumberInt(1),
"Name" : "John"
},
"B2" : {
"_id" : NumberInt(1),
"Name" : "Mary"
}
}
}
{
"_id" : ObjectId("56686341d6389c004c689d6f"),
"Bosses" : {
"B1" : {
"_id" : NumberInt(1),
"Name" : "Mary" // should throw an error
}
}
}
可以用这种结构创建唯一索引吗?