I needed to copy data from one MongoDB database to another. MongoDB supplies the
mongorestore tools to do exactly that. I haven't had to use them lately, so the first thing I do is to check the command line options:
$ mongodump --help Export MongoDB data to BSON files. options: ... -o [ --out ] arg (=dump) output directory or "-" for stdout
-o - is how I write to standard output. I want to dump from here and restore to there, so
mongodump here | mongorestore there is the natural solution.
How do I restore from standard input?
$ mongorestore --help usage: mongorestore [options] [directory or filename to restore from] ...
mongorestore will too:
$ mongorestore - connected to: 127.0.0.1 don't know what to do with file [-]
- is a literal filename. The example input path is in brackets indicating that it's optional; maybe it uses standard input by default if I leave it blank?
$ mongorestore connected to: 127.0.0.1 don't know what to do with file [dump]
All right, I give up. Google, how do I make
mongorestore read from standard input?
- SERVER-4345: mongorestore has no way to accept input from stdin
- SERVER-3111: Allow mongorestore to read from stdin
mongodump can write to standard output, but
mongorestore cannot read from standard input. Reported two years ago, still unfixed.
You can of course dump to a file and then read from a file, and that's what I ended up doing. But… if that's the only permitted mode of operation, why support writing to standard output at all? It's just a useless and frustrating half-feature.
I poked around the MongoDB bug tracker to get a list of other "planned but not scheduled" tickets. As of this writing, an efficient representation of keys (#863), a read-only mode (#563), triggers (#124), and re-adding master-master replication (#2956) – each of them a feature I wanted – remain in that category.
For the record, Postgres95 beta 0.02 (released May 1995) supported
pg_dump | psql.