patch pattern adding property and value by index that is not an array ?

18 views
Skip to first unread message

rabidlemming

unread,
Jan 18, 2017, 7:42:55 AM1/18/17
to RavenDB - 2nd generation document database

hi

so using the patch pattern to add a property to my documents but the issue i have is the property is been created like so

 "test": [
        "First"
    ]


I would expect it to be like this

test":"First"  

My code

using (IDocumentStore store = new DocumentStore { Url = "http://live-test.ravendb.net/", DefaultDatabase = "altha" }){
store.Initialize(); 
using (IDocumentSession session = store.OpenSession()){
store.DatabaseCommands.Patch(
"ParentItems/1",
new[]
{
new PatchRequest
{
Type = PatchCommandType.Add, 
Name = "test", 
Value = "First"
}
});
        }}
    }


if i use this method 

// .DatabaseCommands
// .Patch(
// "ParentItems/1",
// new ScriptedPatchRequest
// {
// Script = "_.extend(this, { 'test': '" + date +  "'});"
// });

it works. Only i dont want to update 1 document i want to update them all . However if i use the update by index method like so

var operation = store
.DatabaseCommands
.UpdateByIndex(
"Raven/DocumentsByEntityName",
new IndexQuery
{
Query = "Tag:ParentItems"
},
new[]
{
new PatchRequest
{
Type = PatchCommandType.Add, 
Name = "FirstName", 
Value = "Patched Name"
}
},
new BulkOperationOptions
{
AllowStale = false
});
operation.WaitForCompletion();


I get this again

"test": [
        "First"
    ]

and not what i want test":"First"  

so how can i get the update by index to crate a property with a value that isnt an array ?

thanks

R

Dan Bishop

unread,
Jan 18, 2017, 9:36:46 AM1/18/17
to RavenDB - 2nd generation document database
You can use ScriptedPatchRequest in conjunction with UpdateByIndex if you want to operate on the whole set of documents. 

The code would look something like this:
store.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
   
new IndexQuery { Query = "Tag:ParentItems" },
   
new ScriptedPatchRequest { Script = "this.test = 'First';" });

Dan

Oren Eini (Ayende Rahien)

unread,
Jan 18, 2017, 9:44:04 AM1/18/17
to ravendb
Type = PatchCommandType.Set, 

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rabidlemming

unread,
Jan 18, 2017, 10:02:28 AM1/18/17
to RavenDB - 2nd generation document database
cool thanks was hoping i could do that :)
Reply all
Reply to author
Forward
0 new messages