如何對巢狀 document 設定驗證
-
假設資料為
{ ssn : "123-45-6789", name : "Mark Hanes", status : "deceased", matching_info: { organs : [ { heart : { size : 7.55 } }, { kidney : { size : 12.00 } }, { lungs : { volume : 10.50 } } ]}, health: { sex: "male", height: 150.00, dob: "05/08/1989", blood_type: "B", HLA_class: 5, weight: 80.04 } }
請問要如何對 health.sex 設定 validator
-
db.runCommand( { collMod: "test", // change collection name validator: { "health.sex": { $in: ["male", "female", /* whatever else */] } }, validationLevel: "moderate" } )
-
原來使用 "." 就可以... 感謝