In MongoGridFS the index on fs.chunks
{ files_is : 1, n : 1 }named files_id_1_n_1 is not created with the unique flag. As a consequence when running in a multi-threaded environment (using multiple connections) every so many file uploads you get a "Command 'filemd5' failed: exception: chunks out of order" error.
Changing:
chunks.EnsureIndex("files_id", "n")
to:
chunks.EnsureIndex(
new IndexKeysBuilder().Ascending("files_id", "n"),
new IndexOptionsBuilder().SetName("files_id_1_n_1").SetUnique(true)
);
fixes the issue. Or am I missing out on something here and is indeed the git code correct?
Also note that the check in the else "files_id_1_n_1" index is missing the 1 at the end of the name.