RavenDB: Updating all null values of properties of all documents to a value

StackOverflow https://stackoverflow.com/questions/19908773

  •  30-07-2022
  •  | 
  •  

質問

I have Documents like this in RavenDB 2.5:

public class SomeDocument {
    public int Id { get;set; }

    ...other properties...

    public bool ShowMember { get;set; }
}

with the ShowMember property being newly added.

Now I want to set ShowMember to true on all documents where it isn't set already.

I tried doing this with Eval Patching like this:

store.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
                new IndexQuery { Query = "Tag:SomeDocuments" },
                new ScriptedPatchRequest() { 
                      Script = @"if(this.ShowMember == null){ 
                                     this.ShowMember = true;
                                 }" });

the operation completes without any errors, but documents that already have ShowMember set are still updated, despite the if

役に立ちましたか?

解決

After playing around with it some more, doing

if(this.ShowMember == undefined)

seems to work.

Both

if(this.ShowMember == null)

and

if(!this.ShowMember)

don't work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top