Skip to content

simonedeponti/mongodb-anonymizer

 
 

Repository files navigation

mongodb-anonymizer

MongoDB anonymzer tool. Export your MongoDB database anonymized from source to target. Replace all sensitive data thanks to faker.

oclif Version License

Usage

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.

Specify list of fields to anonymize

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

Customize replacements

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

Test

Run docker-compose up -d, then run ./test.sh

About

Anonymize MongoDB database with a NodeJS CLI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 86.4%
  • Shell 7.1%
  • JavaScript 4.6%
  • Dockerfile 1.5%
  • Batchfile 0.4%