Currently, we atomically rename a temp collection to the output file name. This fails for indexed and sharded collections.
There are several options. In order of preferences:
1. Write to the collection the user specifies. We'll have to test that, for example, $out and map/reduce can write to indexed and sharded collections.
2. If the above fails for any reason, we can always copy from the temp collection to the output collection. This will be extremely slow, especially if we have to do it client-side, so should be avoided at all costs.