Upgrading MongoClient

56 views
Skip to first unread message

Tim Nelson

unread,
Apr 23, 2014, 9:01:54 AM4/23/14
to lif...@googlegroups.com
In newer versions of the mongo-java-driver the Mongo class has been deprecated in favor of MongoClient. They did this because the new default WriteConcern in MongoClient is SAFE (aka ACKNOWLEDGED) instead of NORMAL (aka UNACKNOWLEDGED).

This impacts lift-mongodb in 2 ways;

Firstly, the code to setup Mongo instances needs to change. We could just update the code to use MongoClient (and MongoClientOptions), but that would be a breaking change. However, since you should only have one instance per JVM this would be a very small breaking change and I'm leaning towards this path.

Would anyone object to this breaking change?

Secondly, with the new default WriteConcern, database operations that do not return properly will now throw an exception. 

This does *not* affect lift-mongo-record's save function, since the WriteConcern is explicitly set when calling it, and will still default to NORMAL.

However, this does affect other lift-mongo-record functions like update and delete. And will affect all of MongoDocument's functions.

Anyone have any thoughts or concerns?

Tim

Antonio Salazar Cardozo

unread,
Apr 23, 2014, 10:14:11 AM4/23/14
to lif...@googlegroups.com
Two thoughts:
 - In line with the mongo folks's decisions, it seems like in Lift 3 at least lift-mongo-record's save function should also default to a SAFE WriteConcern.
   Relatedly, what's our reasoning for decoupling that from the configuration in the Mongo/MongoClient instance?
 - Can we offer an overloaded constructor for Lift 2.6 that takes the old Mongo instance and creates an appropriate MongoClient from it? We can then
   deprecate that constructor with a note about the change in default WriteConcern, and keep Lift 3 with only a MongoClient constructor.

I'm kind of loath to make a breaking change in the 2.x series if there's a reasonably straightforward way to avoid it.
Thanks,
Antonio

Tim Nelson

unread,
Apr 23, 2014, 2:51:47 PM4/23/14
to lif...@googlegroups.com
"Relatedly, what's our reasoning for decoupling that from the configuration in the Mongo/MongoClient instance"

The 4sq engineers did that so you can call save(true) on a MongoRecord, which explicitly sets the WriteConcern to SAFE.

The standard save function (with no arguments) calls save(false). So, we would have to change that to save(true) to default to SAFE. Which would be fine with me for 3.0.

I'll look into a deprecation path for MongoClient. The fact that you can pass a MongoClient where a Mongo is expected should help make that a little easier than I was anticipating.

Tim

Antonio Salazar Cardozo

unread,
Apr 23, 2014, 3:09:46 PM4/23/14
to lif...@googlegroups.com
Interesting. The way save is defined, we technically have a way of marking the save without a write-concern deprecated while allowing
the write-concern a default value. Since 2.6 builds on Scala 2.9+, I think we can redefine:

def save(safe: Boolean = true): MyType

And then have:

@deprecated("save with no argument list is deprecated and will go away in Lift 3; it defaults to an unsafe WriteConcern. Please call save(false) for this behavior. Calling save() will default the WriteConcern to true, which is in line with current default Mongo behavior.", "2.6)
def save: MyType

Some quick Scala console messing indicates this should work.

Thoughts?
Thanks,
Antonio

Tim Nelson

unread,
Apr 23, 2014, 3:49:26 PM4/23/14
to lif...@googlegroups.com
Works for me.

Tim Nelson

unread,
Apr 26, 2014, 9:39:01 AM4/26/14
to lif...@googlegroups.com
I just issued a pull request [1]. See the commit message for details.

Reply all
Reply to author
Forward
0 new messages