scala - Remove case class field before storing to MongoDB -


i'm writing generic update method simplify save case class change mongodb. model t trait has following function:

  def update(id: bsonobjectid, t: t)(implicit writer: oformat[t]): future[writeresult] = {     collection.update(json.obj("_id" -> id), t)   } 

when i'm calling it, fails following error:

caused by: reactivemongo.api.commands.updatewriteresult:  databaseexception['the _id field cannot changed {_id: objectid('4ec58120cd6cad6afc000001')} {_id: "4ec58120cd6cad6afc000001"}.' (code = 16837)] 

which makes sense cause mongodb not allow update document id though same value.

i'm wondering how remove _id case-class instance update in mongodb. guess have tuple instance before converted bson, don't know how that. example case class:

case class user(   _id: bsonobjectid,   email: string } 

thanks

i agree ipoteka. use findandmodify command reactive mongo. there example gist here should help.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -