我是MongoDB的新手,所以也许这是显而易见的。但谷歌搜索没有用。
我建立了一个全新的MongoDB帐户,用accnt'resizer'和密码'test'创建了一个名为'resizer-test'的数据库。然后,我成功地使用Web界面上传了一个名为'flames.jpg'的图像。
然后我尝试使用以下代码和官方C#驱动程序(版本1.3.1)从C#下载文件
string connectionString = "mongodb://resizer:test@staff.mongohq.com:10028/resizer-test";
this.db = MongoDatabase.Create(connectionString);
gridSettings = new MongoGridFSSettings();
grid = db.GetGridFS(gridSettings);
return grid.OpenRead("flames.jpg");
但是立即得到了这个例外:
InvalidOperationException: Duplicate element name 'filename'.
at MongoDB.Bson.BsonDocument.Add(BsonElement element) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\ObjectModel\BsonDocument.cs:line 452
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\ObjectModel\BsonDocument.cs:line 720
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\ObjectModel\BsonDocument.cs:line 393
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs:line 214
at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(BsonBuffer buffer, IBsonSerializationOptions serializationOptions) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoReplyMessage.cs:line 94
at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializationOptions serializationOptions) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 383
at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 263
at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 223
at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 126
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at MongoDB.Driver.GridFS.MongoGridFSFileInfo.Refresh() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFSFileInfo.cs:line 447
at MongoDB.Driver.GridFS.MongoGridFSFileInfo.get_Exists() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFSFileInfo.cs:line 150
at MongoDB.Driver.GridFS.MongoGridFSStream..ctor(MongoGridFSFileInfo fileInfo, FileMode mode, FileAccess access) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFSStream.cs:line 76
at MongoDB.Driver.GridFS.MongoGridFSFileInfo.Open(FileMode mode, FileAccess access) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFSFileInfo.cs:line 408
at MongoDB.Driver.GridFS.MongoGridFSFileInfo.OpenRead() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFSFileInfo.cs:line 416
at MongoDB.Driver.GridFS.MongoGridFS.OpenRead(String remoteFileName) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFS.cs:line 696
at ImageResizer.Plugins.MongoReader.MongoReaderPlugin.MongoVirtualFile.Open() in C:\Users\Administrator\Documents\resizer\Plugins\MongoReader\MongoReaderPlugin.cs:line 79
at ImageResizer.ImageBuilder.GetStreamFromSource(Object source, ResizeSettings settings, Boolean& disposeStream, String& path, Boolean& restoreStreamPosition) in C:\Users\Administrator\Documents\resizer\Core\ImageBuilder.cs:line 253
at ImageResizer.ImageBuilder.LoadImage(Object source, ResizeSettings settings, Boolean restoreStreamPos) in C:\Users\Administrator\Documents\resizer\Core\ImageBuilder.cs:line 135
at ImageResizer.ImageBuilder.BuildJob(ImageJob job) in C:\Users\Administrator\Documents\resizer\Core\ImageBuilder.cs:line 388
at ImageResizer.ImageBuilder.Build(ImageJob job) in C:\Users\Administrator\Documents\resizer\Core\ImageBuilder.cs:line 371
at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource, Boolean addFileExtension) in C:\Users\Administrator\Documents\resizer\Core\ImageBuilder.cs:line 357
at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource) in C:\Users\Administrator\Documents\resizer\Core\ImageBuilder.cs:line 343
at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings) in C:\Users\Administrator\Documents\resizer\Core\ImageBuilder.cs:line 330
at ImageResizer.InterceptModule.<>c__DisplayClass2.<HandleRequest>b__1(Stream stream) in C:\Users\Administrator\Documents\resizer\Core\InterceptModule.cs:line 266
at ImageResizer.Plugins.Basic.NoCacheHandler.ProcessRequest(HttpContext context) in C:\Users\Administrator\Documents\resizer\Core\Plugins\Basic\NoCacheHandler.cs:line 28
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我错过了什么?
答案 0 :(得分:1)
MongoHQ.COM在上传过程中将重复的文件名元素附加到文件中 - 这是他们手动文件管理界面中的一个错误。