Created
December 16, 2019 02:47
-
-
Save bayucandra/d61bb1ef9f5c9303833a11977c7783bb to your computer and use it in GitHub Desktop.
Mongo get duplicate field by using regular expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"regexp" | |
) | |
func main() { | |
errStr := `rpc error: code = AlreadyExists desc = multiple write errors: [{write errors: [{E11000 duplicate key error ` + | |
`collection: mai_webmin_inventory_service.groups index: unique_name dup key: { name: "aa1234" }}]}, {<nil>}]` | |
r := regexp.MustCompile(`(dup key: )(.*)(}]},)`) | |
dupField := r.FindStringSubmatch(errStr)[2] | |
fmt.Println(dupField) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment