当我尝试将大文件(1.8GB)上传到GridFS时,Mongodb似乎任意提前返回。较小的文件工作得很好。
我正在使用 node.js 本机驱动程序。代码(为简洁起见省略了一些内容)如下:
var objectId = new ObjectID(),
gridStore = new GridStore(db, objectId, filename /*declared elsewhere*/, "w", { "content_type": contentType /* declared elsewhere */ }),
obj = {};
gridStore.open(function (err, gs) {
console.log("gridStore open");
gs.writeFile(tempFile, function (err, doc) {
if (err) {
throw err;
}
console.log("file written");
obj.fileId = doc._id;
// double check the md5 of the uploaded file against what was uploaded
// (md5 variable declared elsewhere)
if (doc.md5 !== md5) {
console.log(doc);
console.log(doc.md5);
console.log(md5);
//delete bad file
GridStore.unlink(db, doc.filename, function (err, gridStore) {
if (err) {
throw err;
}
});
} else {
// do the desired stuff
}
});
});
“doc”对象似乎总是以不同的长度返回(显然是不同的 md5)。