我正在使用mongoose创建索引它将检查Name,PName和OName的唯一性(Name + PName + OName应该是唯一的)。请查看以下实施
var MySchema = new mongoose.Schema({
Name: { type: String, required: true},
Details: [{
PName: { type: String, required: true},
OName: { type: String, required: true}
}]
});
MySchema.index({Name: 1, Details.PName: 1, Details.OName:1 }, {unique: true});
文件
{"Name" : "Testing123","Details" : [{"PName" : "Page1", "OName" : "Ob1"},
{"PName" : "Page1", "OName" : "Ob1"}]}
我需要限制上面的文档以便插入,因为Name,PName和OName不是唯一的。