How to know lift mongo record updated successfully or not?

35 views
Skip to first unread message

Abdhesh Kumar

unread,
May 22, 2013, 3:37:15 AM5/22/13
to lif...@googlegroups.com
Hello Guys,
There is way to Know lift mongo record updated successfully or not?
for example .

val user =  User.findByStringId(userid).getOrElse(User).roles(List("admin")).update.

Richard Dallaway

unread,
May 22, 2013, 5:26:33 AM5/22/13
to liftweb
Hello

By "updated successfully" I guess you mean "without error" rather than "did the value actually change".

Mongo has the concept of a "write concern". The traditional default has been UNACKNOWLEDGED (a.k.a "normal").  This concern level was happy if the network was working.

The next step up from that is ACKNOWLEDGED (a.k.a. "safe").  This level gives Mongo the chance to respond with an error. The Mongo docs describe it as: "With this level of write concern, clients can catch network, duplicate key, and other exceptions."

I can't see an obvious way to set the write concern on the update call. My *guess* (sorry!) is that it'll use the driver default. This would make things interesting because the Mongo drivers introduced a new client to change the default to be ACKNOWLEDGED (see: http://docs.mongodb.org/manual/release-notes/drivers-write-concern/).

If you're using a recent Lift 2.5 (e.g., RC6) you could try and replace ...

new Mongo(...)

with...

new MongoClient(....)

...and that could, plausibly, default to updates called with the ACKNOWLEDGED write concern.

Alternatives:

The save method can take a write concern argument.

If you're using Rogue, the updateOne call takes a write concern argument.

Hope that's some help
Richard

 

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
 
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages