How MongoRecord.save(WriteConcern) works

43 views
Skip to first unread message

Taner Sener

unread,
Sep 26, 2012, 3:12:42 PM9/26/12
to lif...@googlegroups.com
Hi,

Sorry if I am asking an easy question but I'm stuck at this point and can't see what I'm missing.

I have a mongo db instance which is protected with username & password.
Username/password is defined by MongoDB.defineDbAuth(.., ..) on initialization

If I remove MongoDB.defineDbAuth(.., ..) line the following code still works without throwing an exception.

According to documentation, setting com.mongodb.WriteConcern.SAFE parameter should throw an exception if save fails. But at this point it is not thrown and my record is not inserted in db.

try {
    myMongoRecord.save(com.mongodb.WriteConcern.SAFE)
} catch {
    case t: Throwable => {
        System.out.println("3")
    }
}

Can you help me to understand the reason?

Thanks,
           

Tim Nelson

unread,
Sep 27, 2012, 8:07:30 AM9/27/12
to lif...@googlegroups.com
Hi Taner,

It shouldn't matter whether you are using authentication or not. WriteConcern.SAFE should throw an exception either way.

I will take a look when I have some time.

Tim

Ben Phelan

unread,
Sep 27, 2012, 12:16:11 PM9/27/12
to lif...@googlegroups.com
I don't know whether this is related or not, but save ignores the connection-level write concern too.  When you're explicitly calling myRecord.save(true) I'm fairly sure you should be seeing the exception though...

Cheers,
Ben
Reply all
Reply to author
Forward
0 new messages