Skip to content

Instantly share code, notes, and snippets.

@rririanto
Last active March 26, 2022 18:35
Show Gist options
  • Save rririanto/5b843b8eecc7b32529e72375af3ccf2e to your computer and use it in GitHub Desktop.
Save rririanto/5b843b8eecc7b32529e72375af3ccf2e to your computer and use it in GitHub Desktop.
Remove _id from Mongoexport result
export MONGODB_URI="mongodb://<username>:<password>@<ip:port>/<database>?authMechanism=SCRAM-SHA-256&readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false"
mongoexport --collection=users --out=users_raw.json --jsonArray --uri=$MONGODB_URI && jq 'map(del(._id))' users_raw.json > users.json
mongoexport --collection=products --out=products_raw.json --jsonArray --uri=$MONGODB_URI && jq 'map(del(._id))' products_raw.json > products.json
@rririanto
Copy link
Author

mongoimport --collection users --file users.json --jsonArray --uri $MONGO_URI_NEW
mongoimport --collection products --file products.json --jsonArray --uri $MONGO_URI_NEW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment