Hello,
In order to check if an error is duplicate key error because index, I have to write mine (because I don’t find how to do this unlike with mgo driver). Is it possible to provide it in the Go driver?
Currently I use this:
// IsDup returns whether err informs of a duplicate key error because
// a primary key index or a secondary unique index already has an entry
// with the given value.
func IsDup(err error) bool {
if wes, ok := err.(mongo.WriteException); ok {
for i := range wes.WriteErrors {
if wes.WriteErrors[i].Code == 11000 || wes.WriteErrors[i].Code == 11001 || wes.WriteErrors[i].Code == 12582 || wes.WriteErrors[i].Code == 16460 {
return true
}
}
}
return false
}
Many thx