Skip to content

Instantly share code, notes, and snippets.

@normgraham
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save normgraham/8743619 to your computer and use it in GitHub Desktop.

Select an option

Save normgraham/8743619 to your computer and use it in GitHub Desktop.
Copy a system.profile collection in a database by dumping it and then restoring it to a new database.collection.
#!/usr/bin/env bash
# Edit the following variables appropriately
SOURCEDB="mydb"
TARGETDB="test"
TARGETCOLL="sp"
mongodump -d $SOURCEDB -c system.profile -o /tmp
mv /tmp/$SOURCEDB/system.profile.bson /tmp/$SOURCEDB/$TARGETCOLL.bson
mongorestore --drop -d $TARGETDB -c $TARGETCOLL /tmp/$SOURCEDB/$TARGETCOLL.bson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment