使用 C# 驱动程序将文件上传到 mongoDB,GridFS 生成断言
首先,设置:
服务器:Ubuntu 10.04服务器
mongod --版本
db版本v1.2.2,pdffile版本4.5
11 月 23 日星期三 11:35:42 git 版本:nogitversion
- < p>客户端:Windows 7 64位,VS2010应用程序,使用官方C#驱动v1.3。
我正在尝试使用 GridFS 在 mongoDB 中存储 png 图像。我的代码如下所示:
var GridFSInfo = DB.GridFS.Upload(TextureFileName, TextureFileName);
运行此代码,出现以下异常
An unhandled exception of type 'MongoDB.Driver.GridFS.MongoGridFSException' occurred in MongoDB.Driver.dll
Additional information: Upload client and server MD5 hashes are not equal.
我试图查找有关此错误的信息,但我似乎是唯一遇到此问题的人:(
服务器日志没有给出任何错误,我全部得到的是:
Wed Nov 23 11:42:23 connection accepted from 141.3.89.168:16861 #159
Wed Nov 23 11:42:25 building new index on { _id: ObjId(000000000000000000000000) } for ObjectDBTest.fs.files...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.files idxNo:0 { name: "_id_", ns: "ObjectDBTest.fs.files", key: { _id: ObjId(000000000000000000000000) } }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:25 info: creating collection ObjectDBTest.fs.files on add index
Wed Nov 23 11:42:25 building new index on { filename: 1, uploadDate: 1 } for ObjectDBTest.fs.files...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.files idxNo:1 { _id: ObjId(4ecccd0382522c02f8e58d75), name: "filename_1_uploadDate_1", ns: "ObjectDBTest.fs.files", key: { filename: 1, uploadDate: 1 } }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:25 building new index on { _id: ObjId(000000000000000000000000) } for ObjectDBTest.fs.chunks...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.chunks idxNo:0 { name: "_id_", ns: "ObjectDBTest.fs.chunks", key: { _id: ObjId(000000000000000000000000) } }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:25 info: creating collection ObjectDBTest.fs.chunks on add index
Wed Nov 23 11:42:25 building new index on { files_id: 1, n: 1 } for ObjectDBTest.fs.chunks...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.chunks idxNo:1 { _id: ObjId(4ecccd0382522c02f8e58d76), name: "files_id_1_n_1", ns: "ObjectDBTest.fs.chunks", key: { files_id: 1, n: 1 }, unique: true }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:29 end connection 141.3.89.168:16861
在我看来,文件传输已启动,但随后出现了问题,我使用 mongofiles 命令行实用程序来查看 GridFS 是否正常工作,但文件上传失败。问题,我的应用程序也可以正常工作。我不进行 GridFS 上传,只使用标准 BSON 文档操作,我可以很好地插入、搜索、删除,所以
我现在不知道这可能是什么。如有任何提示,我将不胜感激。
First of all, the setup:
Server: Ubuntu 10.04 server
mongod --version
db version v1.2.2, pdfile version 4.5
Wed Nov 23 11:35:42 git version: nogitversion
Client: Windows 7 64bit, VS2010 app, using official C# driver v1.3.
I'm trying to store a png image in the mongoDB using the GridFS. My code looks like this:
var GridFSInfo = DB.GridFS.Upload(TextureFileName, TextureFileName);
Running this code I get the following exception
An unhandled exception of type 'MongoDB.Driver.GridFS.MongoGridFSException' occurred in MongoDB.Driver.dll
Additional information: Upload client and server MD5 hashes are not equal.
I have tried to find info on this error, but I seem to be the only person having trouble with this :(
The server log doesn't give any error, all I get is:
Wed Nov 23 11:42:23 connection accepted from 141.3.89.168:16861 #159
Wed Nov 23 11:42:25 building new index on { _id: ObjId(000000000000000000000000) } for ObjectDBTest.fs.files...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.files idxNo:0 { name: "_id_", ns: "ObjectDBTest.fs.files", key: { _id: ObjId(000000000000000000000000) } }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:25 info: creating collection ObjectDBTest.fs.files on add index
Wed Nov 23 11:42:25 building new index on { filename: 1, uploadDate: 1 } for ObjectDBTest.fs.files...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.files idxNo:1 { _id: ObjId(4ecccd0382522c02f8e58d75), name: "filename_1_uploadDate_1", ns: "ObjectDBTest.fs.files", key: { filename: 1, uploadDate: 1 } }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:25 building new index on { _id: ObjId(000000000000000000000000) } for ObjectDBTest.fs.chunks...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.chunks idxNo:0 { name: "_id_", ns: "ObjectDBTest.fs.chunks", key: { _id: ObjId(000000000000000000000000) } }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:25 info: creating collection ObjectDBTest.fs.chunks on add index
Wed Nov 23 11:42:25 building new index on { files_id: 1, n: 1 } for ObjectDBTest.fs.chunks...
Wed Nov 23 11:42:25 Buildindex ObjectDBTest.fs.chunks idxNo:1 { _id: ObjId(4ecccd0382522c02f8e58d76), name: "files_id_1_n_1", ns: "ObjectDBTest.fs.chunks", key: { files_id: 1, n: 1 }, unique: true }
Wed Nov 23 11:42:25 done for 0 records 0secs
Wed Nov 23 11:42:29 end connection 141.3.89.168:16861
This looks to me like the file transfer is initiated but then something goes wrong. I triplechecked that the file exists. I used the mongofiles command line utility to see if the GridFS works and everything is fine there, upload of files is no problem. My app also works fine if I do not make the GridFS upload and only use standard BSON document manipulation. I can insert, search, delete fine, so the connection to the server works.
I'm at a loss now as to what could be the source of this. I'd be thankful for any hints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很容易重现吗?它与特定文件相关吗?如果您有任何重现此问题的提示,请告诉我。
你真的使用v1.2.2的服务器吗?当前版本是2.0.1。
Is this easily reproducible? Is it related to a particular file? Let me know if you have any hints to reproduce this.
Are you really using v1.2.2 of the server? The current version is 2.0.1.