Requirements:
- You use ReactiveMongo & PlayReactiveMongo.
- You speak directly to Mongo with JSON.
- You want to update specific fields of a document.
Here, the Mongo document I will use for my explaination :
{
"personal": {
"name": "RENAULT",
"firstname": "Sébastien"
"address": {
"number": "2",
"street": "Saint-Pierre",
"city: "Chartres"
}
}
}
You want to update only those fields:
{
"personal": {
"name": "Renault",
"address": {
"number": "2"
}
}
}
If you set the original document with this partial document, you will loose some data (firstname, city, street). To not loose any data and update only specific fields, you have to set the document with the following document :
{
"personal.name": "Renault",
"personal.address.number: 2
}
The JSON Object is flattened. The belonging code do the work by flattening a JSON object to this special form.