I have been trying to find a way to do this but cannot, and I have a feeling there isn't an easy way to do what I want.
I have been testing using mongodump | mongorestore as a way to avoid creating an actual stored set of files, which is very useful on a cloud-based service. So far, I have been testing this by specifying the same db, although it technically isn't necessary, like so...
mongodump -h hostname -d dumpdb --excludeCollection bigcollection --archive | mongorestore --archive -d dumpdb --drop
mongodump -h hostname -d dumpdb -c bigcollection --archive --queryFile onlythese.json | mongorestore --archive -d dumpdb -c bigcollection --drop
I have found that these options work best for me; when I attempt to specify the -o -
option with the single db, with the --archive
removed, I was having some issues, but since this worked, I didn't mess with it.
Since I was restoring to the same db and because only the collections that were in there at the time were restored, I realize I can knock off the -d
and -c
in both mongorestore commands. But, it was easy to do, and is the set up for the next step...
All I wanted to do was restore the specified db in two steps, to a db of a different name, like so...
mongodump -h hostname -d dumpdb --excludeCollection bigcollection --archive | mongorestore --archive -d restoredb --drop
mongodump -h hostname -d dumpdb -c bigcollection --archive --queryFile onlythese.json | mongorestore --archive -d restoredb -c bigcollection --drop
The dump works fine, but restore does not. Based on the limited documentation, my assumption is that the dump db and restore db need to be the same for this to work; if the db specified in mongorestore
is not in the dump, it just won't restore.
I find this to be rather annoying; my other thought was to restore the db as is, and just copy it to the other db.
I have thought about using other tools such as mongo-dump-stream, but considering everything was working swimmingly so far, I was hoping that it would work with the default tools.
On another point, I did dump the archive to a file (like so: > dumpdb.tar
) and attempt to restore from there (like so --archive=dumpdb.tar
) which is how I confirmed that the db needed to be in the dump.
Any suggestions/comments/hacks would be welcome.