if someone has the "storageEngine" key in their collection options, it will be returned from the driver as a bson.D instead of a bson.M, and mongodump will write the map out as
[{Name:"...", Value:"..."}, ...]
instead of as a regular map.
Root cause looks like this function, which returns a bson.D, whose values can be marshaled into JSON if the structure is one level deep, but is marshalled as an array if its greater than 1 level deep (like the storageEngine options):
https://github.com/mongodb/mongo-tools/blob/d063f417dcbfdf1ae578fc269a50533f5b9ea2d3/common/db/namespaces.go#L117
to repro:
1. create a collection with additional storageEngine options, e.g.
> db.createCollection("testcoll", {storageEngine:{wiredTiger:{"configString":"block_compressor=snappy"}}}
2. then dump the database
3. then restore it - will get error: "error running create command: 'storageEngine' has to be a document"
Workaround:
Run mongodump as usual, but before restoring, edit the .metadata.json file so that the json object for the storageEngine key matches the correct format, e.g.:
{storageEngine:{wiredTiger:{"configString":"..."}}}