我發現,它可以這樣做:獨特的數組中貓鼬
var someSchema = new Schema({
myArray: [ObjectId], //array of ObjectIds
});
someSchema.index({myArray: 1}, {unique:true});
但此代碼不是爲我工作。所以基本上我試圖做的是創建ObjectID的組合,以後可能不會被複制。
例如:
If myArray is [val1, val2]
Another document with myArray[val1, val2] or myArray[val2, val1] is not allowed
But of course myArray[val1, val3] is allowed, because it is another combination
- 由於