$set and $unset using a DAO

6 views
Skip to first unread message

Pat Ferrel

unread,
May 22, 2017, 4:59:15 PM5/22/17
to scala-salat
I have users, with properties, which are Map[String, String], the user is just:

    case class User ( _id: String, properties: Map[String, String] )

I get an event that tells me to remove or add to the properties and want this to create the object if it does not exist.

    object UsersDAO extends SalatDAO ...

I understand how to use the upsert flag in the DAO but not how to $unset some property's value? Do I have to read the object and create a new one with the correct properties? I thought this is what $set and $unset were designed to avoid.

Noah Zucker

unread,
May 22, 2017, 11:13:29 PM5/22/17
to scala...@googlegroups.com
It's been a while, but my recollection is that in use cases like this, you should write the direct Mongo code (via Casbah) to accomplish what you want.  Salat provides basic CRUD operations, but does not attempt to provide a framework over every possible Mongo operation. You can get access to the actual Mongo connection and via Casbah do what you need.

So, if you have the _id of the record to update, then you just call the $unset or $set calls along with the _id parameter. You don't have to fetch and deserialize the entire object.


--
You received this message because you are subscribed to the Google Groups "scala-salat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-salat+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages