2

I have several documents. Below I will list just two. How do I update the value of the "Value field" that is below the "Name field: StartDate" in all documents?

Example: 10/10/2019 to 09/09/2019 01/01/2019 to 09/09/2019

Document 1:

{
    "IdLoginTwm": 4330,
    "Parametros": [
        {
            "Name": "UserName",
            "Value": "diego.guiando@gmail.com"
        },
        {
            "Name ": "StartDate",
            "Value ": "10/10/2019"
        }
    ]
}  

Document 2:

{
    "IdLoginTwm": 4330,
    "Parametros": [
        {
            "Name": "UserName",
            "Value": "diego.guiando@gmail.com"
        },
        {
            "Name ": "FirstName",
            "Value ": "diego"
        },  
        {
            "Name ": "StartDate",
            "Value ": "01/01/2019"
        }
    ]
}  

Thanks!!

Danielle
  • 3,324
  • 2
  • 18
  • 31

1 Answers1

2

You can use the PatchByQueryOperation() for this.

https://ravendb.net/docs/article-page/4.2/Csharp/client-api/operations/patching/set-based#patching-how-to-perform-set-based-operations-on-documents

The patch script should be similar to below

from Logins
update {
    var res = this.Parametros.filter(x => x.Name == "StartDate")
    if (res.length > 0)
    {
        res.forEach(x => x.Value = 'NULL')
    }
}
garay
  • 636
  • 3
  • 5
  • Hi, I try this but not work. from Logins as l where l.Parametros.Nome = 'StartDate' update { for(var i = 0; i < this.Parametros.length; i++ ){ if( this.Parametros[i].Name == 'StartDate') this.Parametros[i].Value = 'NULL'; } } – Diego Clemente Nov 04 '19 at 13:16