saving an file in gridFs returns error

137 views
Skip to first unread message

Maykon Elias

unread,
Oct 16, 2012, 10:07:34 AM10/16/12
to mongodb...@googlegroups.com
can anyone help me?

my string connection:

saving an image in gridFs returns this error:

MongoDB.Driver.MongoSafeModeException: Safemode detected an error 'need to login'. (response was { "errmsg" : "need to login", "ok" : 0.0 }).
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 509
   at MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1104
   at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document, MongoInsertOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 942
   at MongoDB.Driver.MongoCollection.Insert[TNominalType](TNominalType document, MongoInsertOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 902
   at MongoDB.Driver.MongoCollection`1.Insert(TDefaultDocument document, MongoInsertOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1749
   at MongoDB.Driver.MongoCollection.CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 155
   at MongoDB.Driver.MongoCollection.EnsureIndex(String[] keyNames) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 317
   at MongoDB.Driver.GridFS.MongoGridFS.EnsureIndexes(Int32 maxFiles) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFS.cs:line 458
   at MongoDB.Driver.GridFS.MongoGridFS.EnsureIndexes() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFS.cs:line 417
   at MongoDB.Driver.GridFS.MongoGridFS.Upload(Stream stream, String remoteFileName, MongoGridFSCreateOptions createOptions) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFS.cs:line 782
   at MongoDB.Driver.GridFS.MongoGridFS.Upload(Stream stream, String remoteFileName) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFS.cs:line 765
   at MongoDB.Driver.GridFS.MongoGridFS.Upload(String localFileName, String remoteFileName) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFS.cs:line 903
   at MongoDB.Driver.GridFS.MongoGridFS.Upload(String fileName) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\GridFS\MongoGridFS.cs:line 890
   at System.OneToOne.Mobile.Clientes.File.SetFile(String idFile, String mimeType, String image, String fullName) in C:\Tfs.OneToOne\liente\System.OneToOne.Mobile.Clientes\File.cs:line 18

Norberto Leite

unread,
Nov 16, 2012, 4:09:19 AM11/16/12
to mongodb...@googlegroups.com
Hi Elias, 

I expect you are using authentication and that you have it enabled on the GridFs database. Is this correct?
Which version MongoDB are you using ? 


On Tuesday, October 16, 2012 4:07:34 PM UTC+2, Maykon Elias wrote:
can anyone help me?

my string connection:

Maykon Elias

unread,
Nov 16, 2012, 6:57:06 AM11/16/12
to mongodb...@googlegroups.com
Hi, Norberto

Correct i'm GridFs using to save images, using only authentication connection as shown in the example:
mongodb://name:pa...@mongodb.server.com/test?Safe=false
It has some kind of authentication should I use before saving a file in GridFs?
The version 2.1.1 is MongoDB

Robert Stam

unread,
Nov 16, 2012, 12:01:07 PM11/16/12
to mongodb...@googlegroups.com
I am unable to reproduce this.

Can you show me how you are calling Upload?

Normally credentials provided on the connection string flow down as default credentials from server to database to GridFS, but if you are doing something unusual the credentials might not be reaching the Upload call.

What version of the C# driver (not the server) are you using?

I also recommend that you always use "safe=true" in your connection string instead of "safe=false".

Maykon Elias

unread,
Nov 23, 2012, 1:54:07 PM11/23/12
to mongodb...@googlegroups.com
Hi Robert Stam,
 
The error occurs when trying to insert any document also.
MongoDB.Driver C # version 1.4.2.4500

The following screenshot with error.


Em sexta-feira, 16 de novembro de 2012 15h01min09s UTC-2, Robert Stam escreveu:
I am unable to reproduce this.

Can you show me how you are calling Upload?

Normally credentials provided on the connection string flow down as default credentials from server to database to GridFS, but if you are doing something unusual the credentials might not be reaching the Upload call.

What version of the C# driver (not the server) are you using?

I also recommend that you always use "safe=true" in your connection string instead of "safe=false".

On Fri, Nov 16, 2012 at 6:57 AM, Maykon Elias <mel...@onetooneengine.com.br> wrote:
Hi, Norberto

Correct i'm GridFs using to save images, using only authentication connection as shown in the example:

Robert Stam

unread,
Nov 23, 2012, 5:44:40 PM11/23/12
to mongodb...@googlegroups.com
Thanks for the additional info.

This error is a result of a change made to the server (versions 2.1.0 and newer) that resulted in an incompatibility with older versions of the C# driver when using authentication. Specifically, newer versions of the server require that the getLastError command (that's the command that gets sent to the server when safe=true) be sent to the authenticated database. With previous versions of the server the driver would just sent the getLastError command to the admin database no matter which database the update operation had actually occurred on.


This was fixed in version 1.6 of the C# driver which was released on 2012-08-12.

You are using version 1.4.2 which does not contain the fix.

Maykon Elias

unread,
Dec 4, 2012, 3:05:47 PM12/4/12
to mongodb...@googlegroups.com

Thanks Robert Stam,
I switched to the new Driver, worked perfectly.

Thank you again.
Reply all
Reply to author
Forward
0 new messages