Skip to content

Instantly share code, notes, and snippets.

@aichholzer
Created March 29, 2017 00:21
Show Gist options
  • Save aichholzer/6ce25f9f69fcbc38adfe0be6d79cf9bc to your computer and use it in GitHub Desktop.
Save aichholzer/6ce25f9f69fcbc38adfe0be6d79cf9bc to your computer and use it in GitHub Desktop.
Parse MongoDB duplicate error
'use strict';
let err = 'E11000 duplicate key error collection: home.users index: name_1 dup key: { : "francis" }';
let err = 'E11000 duplicate key error collection: home.users index: email.personal_1 dup key: { : "me@me.com" }';
let [i, field, input] = err.match(/index:\s([.a-z]+).*{\s?\:\s?"(.*)"/i);
console.log(field, input);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment