MongoDB anonymzer tool.
Export your MongoDB database anonymized from source to target. Replace all sensitive data thanks to faker
.
Run this command by giving a source URI and target URI (no need to install first thanks to npx
):
npx mongodb-anonymizer \
--uri=mongodb://localhost:27017/source \
--targetUri=mongodb://localhost:27017/anonymized
☝️ Be careful, since target collections will be removed.
Use --list
option with a comma separated list of column name:
npx mongodb-anonymizer \
--uri=mongodb://localhost:27017/source \
--targetUri=mongodb://localhost:27017/anonymized
--list=email,firstName,lastName,phone
Specifying another list via --list
replace the default automatically anonymized values:
email,name,description,address,city,country,phone,comment,birthdate
You can also specify replacements for a specific collection:
users.email,products.price
You can also choose which faker function you want to use to replace data (default is faker.random.word
):
npx mongodb-anonymizer \
--uri=mongodb://localhost:27017/source \
--targetUri=mongodb://localhost:27017/anonymized
--list=firstName:faker.name.firstName,lastName:faker.name.lastName
👉 You don't need to specify faker function since the command will try to find correct function via column name.
You can use plain text too for static replacements:
npx mongodb-anonymizer \
--uri=mongodb://localhost:27017/source \
--targetUri=mongodb://localhost:27017/anonymized
--list=textcol:hello,jsoncol:{},intcol:12
You can also anonymize nested fields by using a dot notation (you'll be forced to specify them per collection as the first will be the collection):
npx mongodb-anonymizer \
--uri=mongodb://localhost:27017/source \
--targetUri=mongodb://localhost:27017/anonymized
--list=mycoll.nested.field:hello,mycoll.nested.intcol:12
Run docker-compose up -d
, then run ./test.sh