Add Unique index for 'key'

This commit is contained in:
hantmac
2020-01-04 17:29:05 +08:00
parent 8e30d1b3dd
commit c88c3abf85

View File

@@ -93,5 +93,14 @@ func InitMongo() error {
// 赋值给全局mongo session
Session = sess
}
//Add Unique index for 'key'
keyIndex := mgo.Index{
Key: []string{"key"},
Unique: true,
}
s, c := GetCol("nodes")
defer s.Close()
c.EnsureIndex(keyIndex)
return nil
}