Rhinofly / ReactiveMongo-evolutions

[✓] Library that helps with evolutions of BSONDocuments
1 stars 1 forks source link

replace method #3

Closed Adrien-B closed 11 years ago

Adrien-B commented 11 years ago

Being able to replace items value using their previous value.

Example instead of :

def valueFromId(x: Int): String = … 
id = rating[BSONInteger]("id")
newItem = item remove "id" add ("value" -> valueFromId(id.value))

Being able to write something like :

def valueFrom(x:Int) = …
newItem = item replace ("value", valueFrom)
EECOLOR commented 11 years ago

Your suggested syntax does not include "id". Using the current version you could use this:

def valueFromId(x: Int): String = … 
id = rating[Int]("id")
item update ("id" -> valueFromId(id)) rename ("id" -> "value")

My guess is that you would like to add the following signature to update:

def valueFromId(x: Int): String = … 
item update ("id" -> valueFromId) rename ("id" -> "value")

Is that correct?

EECOLOR commented 11 years ago

This is fixed in v0.3. The new syntax would be:

def valueFromId(x: Int): String = … 
item update ("id" -> valueFromId _)