RejectedSoftware Forums

Sign up

MongoDB getLastError failed?

I'm getting a strange exception when calling ensureIndex():

vibe.db.mongo.connection.MongoDriverException@../../../d/vibe.d/source/vibe/db/mongo/connection.d(270):
BSON value is type 'null', expected to be one of [int]

After some investigation, it seems that MongoDB has a problem with
getLastError. I'm outputting the error return value as JSON at
source/vibe/db/mongo/connection.d:262, and this is what I get:

getLastError: {"ok":0,"bad
cmd":{"w":1,"getLastError":1,"j":true},"errmsg":"no such cmd: w"}

This is already strange by itself, it seems MongoDB takes "w" as the
command instead of "getLastError".

But the thrown exception comes from the call to
MongoErrorDescription(), where one of the fields read using get!int()
is missing. When I replace them by opt!int(0), no exception is
thrown, though the problem with MongoDB is of course still there.

So I guess there are two bugs...

Re: MongoDB getLastError failed?

Am Thu, 21 May 2015 14:13:10 +0200
schrieb Marc Schütz schuetzm@gmx.net:

I'm getting a strange exception when calling ensureIndex():

vibe.db.mongo.connection.MongoDriverException@../../../d/vibe.d/source/vibe/db/mongo/connection.d(270):
BSON value is type 'null', expected to be one of [int]

After some investigation, it seems that MongoDB has a problem with
getLastError. I'm outputting the error return value as JSON at
source/vibe/db/mongo/connection.d:262, and this is what I get:

getLastError: {"ok":0,"bad
cmd":{"w":1,"getLastError":1,"j":true},"errmsg":"no such cmd: w"}

This is already strange by itself, it seems MongoDB takes "w" as the
command instead of "getLastError".

But the thrown exception comes from the call to
MongoErrorDescription(), where one of the fields read using
get!int() is missing. When I replace them by opt!int(0), no
exception is thrown, though the problem with MongoDB is of course
still there.

So I guess there are two bugs...

I should add that this happens with vibe.d from Git and MongoDB 2.4.13.

Re: MongoDB getLastError failed?

I didn't test the change yet, but my guess is that this happens due to the command fields being in a wrong order, probably due to the recent AA changes. I've changed the code to write out the fields in fixed order instead of using an AA: 9294786

Re: MongoDB getLastError failed?

Am Thu, 21 May 2015 18:08:13 GMT
schrieb "Sönke Ludwig" sludwig@rejectedsoftware.com:

I didn't test the change yet, but my guess is that this happens due
to the command fields being in a wrong order, probably due to the
recent AA changes. I've changed the code to write out the fields in
fixed order instead of using an AA:
9294786

Yes, that fixes it.

I would have thought that order doesn't matter (as for JSON), but it
seems BSON is different here...

I can now see what the actual underlying error is: "journaling not
enabled on this server" => so that's my fault then...

Thanks for the quick fix!