When we dump a single collection "foo" with data we end up with two files:
foo.bson and foo.metadata.json which will at a minimum have the following content:
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"db.foo"}]}
When we dump out a read-only view as a collection due to option "--viewsAsCollections" to mongodump, we only write out a single file, fooview.bson and not the metadata.json file.
This can result in failure to overwrite a previously written <foo>.metadata.json file that's already in the dump directory (for instance from previous attempt to dump the view without correct flag).
We should always create the metadata.json file when dumping out view as a collection, so it looks exactly the same as if it were a collection to mongorestore.