且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MongoDB在多个字段上的唯一索引

更新时间:2021-08-20 22:26:51

您无法创建唯一的索引,因为您已经有了&年龄不是唯一的!检查保罗21岁如果您修复该值.创建索引的***方法就是这种方法db.test.createIndex({"name":1,"age":1},{unique:true})

You aren't able to create that index unique because you 've got the name & age not unique! Check Paul 21 years olds If you fix that value. The best way to create the index is this one db.test.createIndex({"name":1, "age":1}, {unique:true})