I have a roadblock i've hit that I can't seem to find an answer too.
I have an array of strings, and I want to replace one of the values in
that array for all documents.
I found "set-based updates" in the HTML API, which looks close to what
I want to do. Basically I have my document:
store.DatabaseCommands.UpdateByIndex("YourIndex", new IndexQuery { Query = "Note:old"
}, new PatchRequest[]
{ new PatchRequest { Name = "Comment", Type = PatchCommandType.Modify, Nested = new PatchRequest[] { new PatchRequest { Type = PatchCommandType.Remove, Value = "old"
},
new PatchRequest { Type = PatchCommandType.Add, Value = "new" },
} }, }, true); On Mon, Apr 11, 2011 at 4:27 PM, Mike Sopinka <msopi...@gmail.com> wrote: > Hello,
> I have a roadblock i've hit that I can't seem to find an answer too. > I have an array of strings, and I want to replace one of the values in > that array for all documents.
> I found "set-based updates" in the HTML API, which looks close to what > I want to do. Basically I have my document:
Thank you very much, I'm on my way! The only issue I have is that I'm
getting an exception that says: Unable to cast object of type
'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.
Also, it is actually an IList<string>, not an array, but the JSON was
still correct above.
My query is as follows: (oldTagName and newTagName are strings, as is
the list trying to be modified)
session.Advanced.DatabaseCommands.UpdateByIndex("MyIndex",
new IndexQuery
{
Query = "Notes:" + oldTagName
},
new PatchRequest[]
{
new PatchRequest
{
Name = "Comment.Notes",
Type = PatchCommandType.Modify,
AllPositions = true,
Nested = new PatchRequest[]
{
new PatchRequest
{
Type = PatchCommandType.Remove,
Value = oldTagName
},
new PatchRequest
{
Type = PatchCommandType.Add,
Value = newTagName
}
}
}
},
false
);
Any ideas that pop into mind?
Thanks,
Mike
On Apr 11, 9:34 am, Ayende Rahien <aye...@ayende.com> wrote:
> store.DatabaseCommands.UpdateByIndex("YourIndex", new IndexQuery
> {
> Query = "Note:old"}, new PatchRequest[]
> {
> new PatchRequest
> {
> Name = "Comment",
> Type = PatchCommandType.Modify,
> Nested = new PatchRequest[]
> {
> new PatchRequest
> {
> Type = PatchCommandType.Remove,
> Value = "old"},
> new PatchRequest
> {
> Type = PatchCommandType.Add,
> Value = "new"
> },
> }
> },
> }, true);
> On Mon, Apr 11, 2011 at 4:27 PM, Mike Sopinka <msopi...@gmail.com> wrote:
> > Hello,
> > I have a roadblock i've hit that I can't seem to find an answer too.
> > I have an array of strings, and I want to replace one of the values in
> > that array for all documents.
> > I found "set-based updates" in the HTML API, which looks close to what
> > I want to do. Basically I have my document:
store.DatabaseCommands.UpdateByIndex("MyIndex", new IndexQuery { Query = "note:" + oldTagName }, new[] { new PatchRequest { Name = "Comment", Type = PatchCommandType.Modify, AllPositions = true, Nested = new[] { new PatchRequest { Type = PatchCommandType.Remove, Name = "Notes", Value = oldTagName }, new PatchRequest { Type = PatchCommandType.Add, Name = "Notes", Value = "new" } } } }, false );
On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com> wrote: > Thank you very much, I'm on my way! The only issue I have is that I'm > getting an exception that says: Unable to cast object of type > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.
> Also, it is actually an IList<string>, not an array, but the JSON was > still correct above.
> My query is as follows: (oldTagName and newTagName are strings, as is > the list trying to be modified)
> session.Advanced.DatabaseCommands.UpdateByIndex("MyIndex", > new IndexQuery > { > Query = "Notes:" + oldTagName > }, > new PatchRequest[] > { > new PatchRequest > { > Name = "Comment.Notes", > Type = PatchCommandType.Modify, > AllPositions = true, > Nested = new PatchRequest[] > { > new PatchRequest > { > Type = PatchCommandType.Remove, > Value = oldTagName > }, > new PatchRequest > { > Type = PatchCommandType.Add, > Value = newTagName > } > } > } > }, > false > );
> Any ideas that pop into mind?
> Thanks, > Mike
> On Apr 11, 9:34 am, Ayende Rahien <aye...@ayende.com> wrote: > > It will look something like:
> > store.DatabaseCommands.UpdateByIndex("YourIndex", new IndexQuery > > { > > Query = "Note:old"}, new PatchRequest[]
> > { > > new PatchRequest > > { > > Name = "Comment", > > Type = PatchCommandType.Modify, > > Nested = new PatchRequest[] > > { > > new PatchRequest > > { > > Type = PatchCommandType.Remove, > > Value = "old"},
> > new PatchRequest > > { > > Type = PatchCommandType.Add, > > Value = "new" > > },
> > } > > }, > > }, true); > > On Mon, Apr 11, 2011 at 4:27 PM, Mike Sopinka <msopi...@gmail.com> > wrote: > > > Hello,
> > > I have a roadblock i've hit that I can't seem to find an answer too. > > > I have an array of strings, and I want to replace one of the values in > > > that array for all documents.
> > > I found "set-based updates" in the HTML API, which looks close to what > > > I want to do. Basically I have my document:
Since "Notes" was a list, it had a $type and $values when I looked at
the document in the web interface. So instead of setting the "Name"
to "Notes" in the nested patching, I set it to $values, and this did
the trick. It's working as I'd like!
Thank you so much for your help Ayende!
On Apr 12, 9:21 am, Ayende Rahien <aye...@ayende.com> wrote:
> store.DatabaseCommands.UpdateByIndex("MyIndex",
> new IndexQuery
> {
> Query = "note:" + oldTagName
> },
> new[]
> {
> new PatchRequest
> {
> Name = "Comment",
> Type = PatchCommandType.Modify,
> AllPositions = true,
> Nested = new[]
> {
> new PatchRequest
> {
> Type = PatchCommandType.Remove,
> Name = "Notes",
> Value = oldTagName
> },
> new PatchRequest
> {
> Type = PatchCommandType.Add,
> Name = "Notes",
> Value = "new"
> }
> }
> }
> },
> false
> );
> On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com> wrote:
> > Thank you very much, I'm on my way! The only issue I have is that I'm
> > getting an exception that says: Unable to cast object of type
> > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.
> > Also, it is actually an IList<string>, not an array, but the JSON was
> > still correct above.
> > My query is as follows: (oldTagName and newTagName are strings, as is
> > the list trying to be modified)
> > session.Advanced.DatabaseCommands.UpdateByIndex("MyIndex",
> > new IndexQuery
> > {
> > Query = "Notes:" + oldTagName
> > },
> > new PatchRequest[]
> > {
> > new PatchRequest
> > {
> > Name = "Comment.Notes",
> > Type = PatchCommandType.Modify,
> > AllPositions = true,
> > Nested = new PatchRequest[]
> > {
> > new PatchRequest
> > {
> > Type = PatchCommandType.Remove,
> > Value = oldTagName
> > },
> > new PatchRequest
> > {
> > Type = PatchCommandType.Add,
> > Value = newTagName
> > }
> > }
> > }
> > },
> > false
> > );
> > Any ideas that pop into mind?
> > Thanks,
> > Mike
> > On Apr 11, 9:34 am, Ayende Rahien <aye...@ayende.com> wrote:
> > > It will look something like:
> > > store.DatabaseCommands.UpdateByIndex("YourIndex", new IndexQuery
> > > {
> > > Query = "Note:old"}, new PatchRequest[]
> > > {
> > > new PatchRequest
> > > {
> > > Name = "Comment",
> > > Type = PatchCommandType.Modify,
> > > Nested = new PatchRequest[]
> > > {
> > > new PatchRequest
> > > {
> > > Type = PatchCommandType.Remove,
> > > Value = "old"},
> > > new PatchRequest
> > > {
> > > Type = PatchCommandType.Add,
> > > Value = "new"
> > > },
> > > > I have a roadblock i've hit that I can't seem to find an answer too.
> > > > I have an array of strings, and I want to replace one of the values in
> > > > that array for all documents.
> > > > I found "set-based updates" in the HTML API, which looks close to what
> > > > I want to do. Basically I have my document:
I'm trying to do something similar using code from Oren above, but it doesn't seem to be working. I have Roles documents that have a Permissions array, and I'm trying to remove a permission from all users.
An example role document: { "Name": "LC Administrator", "Permissions": [ "Read", "Write", "Delete", "ViewPerformanceDiagnostics", "PreviewEmailsInBrowser", "ManageUsers" ], "CreatedOn": "0001-01-01T00:00:00.0000000", "CreatedBy": null, "ModifiedOn": "2012-07-18T18:13:25.4103944Z", "ModifiedBy": "users/1", "IsDeleted": false
}
I'm trying to remove the "Read" value with this code. It doesn't error or anything, it just doesn't seem to be removing that value at all.
RavenSession.Advanced.DocumentStore.DatabaseCommands .PutIndex("Roles/All", new IndexDefinitionBuilder<Role> { Map = roles => from role in roles select new {role.Name, role.Permissions, role.IsDeleted} });
RavenSession.Advanced.DocumentStore.DatabaseCommands .UpdateByIndex("Roles/All", new IndexQuery{Query="IsDeleted:false"}, new[] { new PatchRequest { Name = "Permissions", Type = PatchCommandType.Modify, AllPositions = true, Nested = new[] { new PatchRequest { Type = PatchCommandType.Remove, Value = "Read" } } } }, true);
This is my first attempt at a patch like this, so I'm not sure if I'm doing anything wrong in here or if the syntax has changed since this original post.
On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
> Since "Notes" was a list, it had a $type and $values when I looked at > the document in the web interface. So instead of setting the "Name" > to "Notes" in the nested patching, I set it to $values, and this did > the trick. It's working as I'd like!
> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com> > wrote: > > > Thank you very much, I'm on my way! The only issue I have is that I'm > > > getting an exception that says: Unable to cast object of type > > > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.
> > > Also, it is actually an IList<string>, not an array, but the JSON was > > > still correct above.
> > > My query is as follows: (oldTagName and newTagName are strings, as is > > > the list trying to be modified)
> > > > > I have a roadblock i've hit that I can't seem to find an answer > too. > > > > > I have an array of strings, and I want to replace one of the > values in > > > > > that array for all documents.
> > > > > I found "set-based updates" in the HTML API, which looks close to > what > > > > > I want to do. Basically I have my document:
On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com> wrote:
> I'm trying to do something similar using code from Oren above, but it
> doesn't seem to be working. I have Roles documents that have a Permissions
> array, and I'm trying to remove a permission from all users.
> I'm trying to remove the "Read" value with this code. It doesn't error or
> anything, it just doesn't seem to be removing that value at all.
> RavenSession.Advanced.DocumentStore.DatabaseCommands
> .PutIndex("Roles/All",
> new IndexDefinitionBuilder<Role>
> {
> Map = roles => from role in roles
> select new {role.Name, role.Permissions, role.IsDeleted}
> });
> RavenSession.Advanced.DocumentStore.DatabaseCommands
> .UpdateByIndex("Roles/All",
> new IndexQuery{Query="IsDeleted:false"},
> new[]
> {
> new PatchRequest
> {
> Name = "Permissions",
> Type = PatchCommandType.Modify,
> AllPositions = true,
> Nested =
> new[]
> {
> new PatchRequest
> {
> Type = PatchCommandType.Remove,
> Value = "Read"
> }
> }
> }
> }, true);
> This is my first attempt at a patch like this, so I'm not sure if I'm
> doing anything wrong in here or if the syntax has changed since this
> original post.
> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>> Since "Notes" was a list, it had a $type and $values when I looked at
>> the document in the web interface. So instead of setting the "Name"
>> to "Notes" in the nested patching, I set it to $values, and this did
>> the trick. It's working as I'd like!
>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com>
>> wrote:
>> > > Thank you very much, I'm on my way! The only issue I have is that
>> I'm
>> > > getting an exception that says: Unable to cast object of type
>> > > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'*
>> *.
>> > > Also, it is actually an IList<string>, not an array, but the JSON was
>> > > still correct above.
>> > > My query is as follows: (oldTagName and newTagName are strings, as is
>> > > the list trying to be modified)
>> > > > > I have a roadblock i've hit that I can't seem to find an answer
>> too.
>> > > > > I have an array of strings, and I want to replace one of the
>> values in
>> > > > > that array for all documents.
>> > > > > I found "set-based updates" in the HTML API, which looks close to
>> what
>> > > > > I want to do. Basically I have my document:
System.InvalidCastException: Unable to cast object of type 'Raven.Json.Linq.RavenJValue' to type 'Raven.Json.Linq.RavenJObject'. at Raven.Json.Linq.Extensions.Convert[U](RavenJToken token, Boolean cast) in c:\Builds\RavenDB-Stable\Raven.Abstractions\Json\Linq\Extensions.cs:line 131
On Thursday, July 19, 2012 5:35:04 PM UTC-5, Oren Eini wrote:
> Remove AllPositions = true,
> What happens then?
> On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com> wrote:
>> I'm trying to do something similar using code from Oren above, but it >> doesn't seem to be working. I have Roles documents that have a Permissions >> array, and I'm trying to remove a permission from all users.
>> I'm trying to remove the "Read" value with this code. It doesn't error or >> anything, it just doesn't seem to be removing that value at all.
>> RavenSession.Advanced.DocumentStore.DatabaseCommands >> .PutIndex("Roles/All", >> new IndexDefinitionBuilder<Role> >> { >> Map = roles => from role in roles >> select new {role.Name, role.Permissions, role.IsDeleted} >> });
>> RavenSession.Advanced.DocumentStore.DatabaseCommands >> .UpdateByIndex("Roles/All", >> new IndexQuery{Query="IsDeleted:false"}, >> new[] >> { >> new PatchRequest >> { >> Name = "Permissions", >> Type = PatchCommandType.Modify, >> AllPositions = true, >> Nested = >> new[] >> { >> new PatchRequest >> { >> Type = PatchCommandType.Remove, >> Value = "Read" >> } >> } >> } >> }, true);
>> This is my first attempt at a patch like this, so I'm not sure if I'm >> doing anything wrong in here or if the syntax has changed since this >> original post.
>> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>>> Since "Notes" was a list, it had a $type and $values when I looked at >>> the document in the web interface. So instead of setting the "Name" >>> to "Notes" in the nested patching, I set it to $values, and this did >>> the trick. It's working as I'd like!
>>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com> >>> wrote: >>> > > Thank you very much, I'm on my way! The only issue I have is that >>> I'm >>> > > getting an exception that says: Unable to cast object of type >>> > > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject' >>> **.
>>> > > Also, it is actually an IList<string>, not an array, but the JSON >>> was >>> > > still correct above.
>>> > > My query is as follows: (oldTagName and newTagName are strings, as >>> is >>> > > the list trying to be modified)
>>> > > > > I have a roadblock i've hit that I can't seem to find an answer >>> too. >>> > > > > I have an array of strings, and I want to replace one of the >>> values in >>> > > > > that array for all documents.
>>> > > > > I found "set-based updates" in the HTML API, which looks close >>> to what >>> > > > > I want to do. Basically I have my document:
})
On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com> wrote:
> I'm trying to do something similar using code from Oren above, but it
> doesn't seem to be working. I have Roles documents that have a Permissions
> array, and I'm trying to remove a permission from all users.
> I'm trying to remove the "Read" value with this code. It doesn't error or
> anything, it just doesn't seem to be removing that value at all.
> RavenSession.Advanced.DocumentStore.DatabaseCommands
> .PutIndex("Roles/All",
> new IndexDefinitionBuilder<Role>
> {
> Map = roles => from role in roles
> select new {role.Name, role.Permissions, role.IsDeleted}
> });
> RavenSession.Advanced.DocumentStore.DatabaseCommands
> .UpdateByIndex("Roles/All",
> new IndexQuery{Query="IsDeleted:false"},
> new[]
> {
> new PatchRequest
> {
> Name = "Permissions",
> Type = PatchCommandType.Modify,
> AllPositions = true,
> Nested =
> new[]
> {
> new PatchRequest
> {
> Type = PatchCommandType.Remove,
> Value = "Read"
> }
> }
> }
> }, true);
> This is my first attempt at a patch like this, so I'm not sure if I'm
> doing anything wrong in here or if the syntax has changed since this
> original post.
> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>> Since "Notes" was a list, it had a $type and $values when I looked at
>> the document in the web interface. So instead of setting the "Name"
>> to "Notes" in the nested patching, I set it to $values, and this did
>> the trick. It's working as I'd like!
>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com>
>> wrote:
>> > > Thank you very much, I'm on my way! The only issue I have is that
>> I'm
>> > > getting an exception that says: Unable to cast object of type
>> > > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'*
>> *.
>> > > Also, it is actually an IList<string>, not an array, but the JSON was
>> > > still correct above.
>> > > My query is as follows: (oldTagName and newTagName are strings, as is
>> > > the list trying to be modified)
>> > > > > I have a roadblock i've hit that I can't seem to find an answer
>> too.
>> > > > > I have an array of strings, and I want to replace one of the
>> values in
>> > > > > that array for all documents.
>> > > > > I found "set-based updates" in the HTML API, which looks close to
>> what
>> > > > > I want to do. Basically I have my document:
I updated to the latest unstable just now (2042) and tried that code, but it doesn't compile. It can't convert from AdvancedPatchRequest to PatchRequest.
RavenSession.Advanced.DocumentStore.DatabaseCommands.Patch("roles/1", new PatchRequest[]{ new AdvancedPatchRequest { Script = "this.Permissions.Remove(perm);", Values = {{"perm", "Read"}} }
> On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com> wrote:
>> I'm trying to do something similar using code from Oren above, but it >> doesn't seem to be working. I have Roles documents that have a Permissions >> array, and I'm trying to remove a permission from all users.
>> I'm trying to remove the "Read" value with this code. It doesn't error or >> anything, it just doesn't seem to be removing that value at all.
>> RavenSession.Advanced.DocumentStore.DatabaseCommands >> .PutIndex("Roles/All", >> new IndexDefinitionBuilder<Role> >> { >> Map = roles => from role in roles >> select new {role.Name, role.Permissions, role.IsDeleted} >> });
>> RavenSession.Advanced.DocumentStore.DatabaseCommands >> .UpdateByIndex("Roles/All", >> new IndexQuery{Query="IsDeleted:false"}, >> new[] >> { >> new PatchRequest >> { >> Name = "Permissions", >> Type = PatchCommandType.Modify, >> AllPositions = true, >> Nested = >> new[] >> { >> new PatchRequest >> { >> Type = PatchCommandType.Remove, >> Value = "Read" >> } >> } >> } >> }, true);
>> This is my first attempt at a patch like this, so I'm not sure if I'm >> doing anything wrong in here or if the syntax has changed since this >> original post.
>> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>>> Since "Notes" was a list, it had a $type and $values when I looked at >>> the document in the web interface. So instead of setting the "Name" >>> to "Notes" in the nested patching, I set it to $values, and this did >>> the trick. It's working as I'd like!
>>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com> >>> wrote: >>> > > Thank you very much, I'm on my way! The only issue I have is that >>> I'm >>> > > getting an exception that says: Unable to cast object of type >>> > > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject' >>> **.
>>> > > Also, it is actually an IList<string>, not an array, but the JSON >>> was >>> > > still correct above.
>>> > > My query is as follows: (oldTagName and newTagName are strings, as >>> is >>> > > the list trying to be modified)
>>> > > > > I have a roadblock i've hit that I can't seem to find an answer >>> too. >>> > > > > I have an array of strings, and I want to replace one of the >>> values in >>> > > > > that array for all documents.
>>> > > > > I found "set-based updates" in the HTML API, which looks close >>> to what >>> > > > > I want to do. Basically I have my document:
On Monday, July 23, 2012 5:36:49 PM UTC-4, Jon Wynveen wrote: > I updated to the latest unstable just now (2042) and tried that code, but > it doesn't compile. It can't convert from AdvancedPatchRequest to > PatchRequest.
On Monday, July 23, 2012 8:49:47 PM UTC-4, Troy wrote: > You may need to get the Nuget package Rx-Linq .. I think this is the one I > needed to make it compile..
> On Monday, July 23, 2012 5:36:49 PM UTC-4, Jon Wynveen wrote:
>> I updated to the latest unstable just now (2042) and tried that code, but >> it doesn't compile. It can't convert from AdvancedPatchRequest to >> PatchRequest.
> I updated to the latest unstable just now (2042) and tried that code, but
> it doesn't compile. It can't convert from AdvancedPatchRequest to
> PatchRequest.
> On Saturday, July 21, 2012 3:01:51 AM UTC-5, Oren Eini wrote:
>> Hm,
>> The code assumes that if you are going to modify arrays, they are going
>> to be arrays of objects.
>> You can't do that using the Patch API.
>> On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com>wrote:
>>> I'm trying to do something similar using code from Oren above, but it
>>> doesn't seem to be working. I have Roles documents that have a Permissions
>>> array, and I'm trying to remove a permission from all users.
>>> I'm trying to remove the "Read" value with this code. It doesn't error
>>> or anything, it just doesn't seem to be removing that value at all.
>>> RavenSession.Advanced.**DocumentStore.DatabaseCommands
>>> .PutIndex("Roles/All",
>>> new IndexDefinitionBuilder<Role>
>>> {
>>> Map = roles => from role in roles
>>> select new {role.Name, role.Permissions, role.IsDeleted}
>>> });
>>> RavenSession.Advanced.**DocumentStore.DatabaseCommands
>>> .UpdateByIndex("Roles/All",
>>> new IndexQuery{Query="IsDeleted:**false"},
>>> new[]
>>> {
>>> new PatchRequest
>>> {
>>> Name = "Permissions",
>>> Type = PatchCommandType.Modify,
>>> AllPositions = true,
>>> Nested =
>>> new[]
>>> {
>>> new PatchRequest
>>> {
>>> Type = PatchCommandType.Remove,
>>> Value = "Read"
>>> }
>>> }
>>> }
>>> }, true);
>>> This is my first attempt at a patch like this, so I'm not sure if I'm
>>> doing anything wrong in here or if the syntax has changed since this
>>> original post.
>>> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>>>> Since "Notes" was a list, it had a $type and $values when I looked at
>>>> the document in the web interface. So instead of setting the "Name"
>>>> to "Notes" in the nested patching, I set it to $values, and this did
>>>> the trick. It's working as I'd like!
>>>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com>
>>>> wrote:
>>>> > > Thank you very much, I'm on my way! The only issue I have is that
>>>> I'm
>>>> > > getting an exception that says: Unable to cast object of type
>>>> > > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'
>>>> ****.
>>>> > > Also, it is actually an IList<string>, not an array, but the JSON
>>>> was
>>>> > > still correct above.
>>>> > > My query is as follows: (oldTagName and newTagName are strings, as
>>>> is
>>>> > > the list trying to be modified)
>>>> > > > > I have a roadblock i've hit that I can't seem to find an answer
>>>> too.
>>>> > > > > I have an array of strings, and I want to replace one of the
>>>> values in
>>>> > > > > that array for all documents.
>>>> > > > > I found "set-based updates" in the HTML API, which looks close
>>>> to what
>>>> > > > > I want to do. Basically I have my document:
On Monday, 23 July 2012 22:36:49 UTC+1, Jon Wynveen wrote:
> I updated to the latest unstable just now (2042) and tried that code, but > it doesn't compile. It can't convert from AdvancedPatchRequest to > PatchRequest.
> On Saturday, July 21, 2012 3:01:51 AM UTC-5, Oren Eini wrote:
>> Hm, >> The code assumes that if you are going to modify arrays, they are going >> to be arrays of objects. >> You can't do that using the Patch API.
>> On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com>wrote:
>>> I'm trying to do something similar using code from Oren above, but it >>> doesn't seem to be working. I have Roles documents that have a Permissions >>> array, and I'm trying to remove a permission from all users.
>>> I'm trying to remove the "Read" value with this code. It doesn't error >>> or anything, it just doesn't seem to be removing that value at all.
>>> RavenSession.Advanced.DocumentStore.DatabaseCommands >>> .PutIndex("Roles/All", >>> new IndexDefinitionBuilder<Role> >>> { >>> Map = roles => from role in roles >>> select new {role.Name, role.Permissions, role.IsDeleted} >>> });
>>> RavenSession.Advanced.DocumentStore.DatabaseCommands >>> .UpdateByIndex("Roles/All", >>> new IndexQuery{Query="IsDeleted:false"}, >>> new[] >>> { >>> new PatchRequest >>> { >>> Name = "Permissions", >>> Type = PatchCommandType.Modify, >>> AllPositions = true, >>> Nested = >>> new[] >>> { >>> new PatchRequest >>> { >>> Type = PatchCommandType.Remove, >>> Value = "Read" >>> } >>> } >>> } >>> }, true);
>>> This is my first attempt at a patch like this, so I'm not sure if I'm >>> doing anything wrong in here or if the syntax has changed since this >>> original post.
>>> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>>>> Since "Notes" was a list, it had a $type and $values when I looked at >>>> the document in the web interface. So instead of setting the "Name" >>>> to "Notes" in the nested patching, I set it to $values, and this did >>>> the trick. It's working as I'd like!
>>>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com> >>>> wrote: >>>> > > Thank you very much, I'm on my way! The only issue I have is that >>>> I'm >>>> > > getting an exception that says: Unable to cast object of type >>>> > > 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject' >>>> **.
>>>> > > Also, it is actually an IList<string>, not an array, but the JSON >>>> was >>>> > > still correct above.
>>>> > > My query is as follows: (oldTagName and newTagName are strings, as >>>> is >>>> > > the list trying to be modified)
>>>> > > > > I have a roadblock i've hit that I can't seem to find an answer >>>> too. >>>> > > > > I have an array of strings, and I want to replace one of the >>>> values in >>>> > > > > that array for all documents.
>>>> > > > > I found "set-based updates" in the HTML API, which looks close >>>> to what >>>> > > > > I want to do. Basically I have my document:
I found that I had updated my version of RavenDB.Database, but not
RavenDB.Client. Once I did that it compiled (using the single
AdvancedPatchRequest, not an array). But now when I try to run it, I'm
getting this error:
>> System.ArgumentException: Batching only supports PUT, PATCH and DELETE.
> at Raven.Database.Data.CommandDataFactory.CreateCommand(RavenJObject
>> jsonCommand, TransactionInformation transactionInformation) in
>> c:\Builds\RavenDB-Stable\Raven.Database\Data\CommandDataFactory.cs:line 53
> at
>> Raven.Database.Server.Responders.DocumentBatch.<>c__DisplayClassa.<Batch>b_ _5(RavenJObject
>> jsonCommand) in
>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>> 76
> at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
> at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
> at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
> at Raven.Database.Server.Responders.DocumentBatch.Batch(IHttpContext
>> context) in
>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>> 75
> at Raven.Database.Server.Responders.DocumentBatch.Respond(IHttpContext
>> context) in
>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>> 38
> at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx) in
>> c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 550
> at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext
>> ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line
>> 316
For clarity, here is my code as it stands now:
RavenSession.Advanced.DocumentStore.DatabaseCommands.Patch("roles/1", new
> On Monday, 23 July 2012 22:36:49 UTC+1, Jon Wynveen wrote:
>> I updated to the latest unstable just now (2042) and tried that code, but
>> it doesn't compile. It can't convert from AdvancedPatchRequest to
>> PatchRequest.
>> On Saturday, July 21, 2012 3:01:51 AM UTC-5, Oren Eini wrote:
>>> Hm,
>>> The code assumes that if you are going to modify arrays, they are going
>>> to be arrays of objects.
>>> You can't do that using the Patch API.
>>> If you can use the new unstable, this becomes:
>>> On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com>wrote:
>>>> I'm trying to do something similar using code from Oren above, but it
>>>> doesn't seem to be working. I have Roles documents that have a Permissions
>>>> array, and I'm trying to remove a permission from all users.
>>>> I'm trying to remove the "Read" value with this code. It doesn't error
>>>> or anything, it just doesn't seem to be removing that value at all.
>>>> RavenSession.Advanced.**DocumentStore.DatabaseCommands
>>>> .PutIndex("Roles/All",
>>>> new IndexDefinitionBuilder<Role>
>>>> {
>>>> Map = roles => from role in roles
>>>> select new {role.Name, role.Permissions, role.IsDeleted}
>>>> });
>>>> RavenSession.Advanced.**DocumentStore.DatabaseCommands
>>>> .UpdateByIndex("Roles/All",
>>>> new IndexQuery{Query="IsDeleted:**false"},
>>>> new[]
>>>> {
>>>> new PatchRequest
>>>> {
>>>> Name = "Permissions",
>>>> Type = PatchCommandType.Modify,
>>>> AllPositions = true,
>>>> Nested =
>>>> new[]
>>>> {
>>>> new PatchRequest
>>>> {
>>>> Type = PatchCommandType.Remove,
>>>> Value = "Read"
>>>> }
>>>> }
>>>> }
>>>> }, true);
>>>> This is my first attempt at a patch like this, so I'm not sure if I'm
>>>> doing anything wrong in here or if the syntax has changed since this
>>>> original post.
>>>> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>>>>> Since "Notes" was a list, it had a $type and $values when I looked at
>>>>> the document in the web interface. So instead of setting the "Name"
>>>>> to "Notes" in the nested patching, I set it to $values, and this did
>>>>> the trick. It's working as I'd like!
>>>>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com>
>>>>> wrote:
>>>>> > > Thank you very much, I'm on my way! The only issue I have is that
>>>>> I'm
>>>>> > > getting an exception that says: Unable to cast object of type
>>>>> > > 'Newtonsoft.Json.Linq.JValue' to type
>>>>> 'Newtonsoft.Json.Linq.JObject'****.
>>>>> > > Also, it is actually an IList<string>, not an array, but the JSON
>>>>> was
>>>>> > > still correct above.
>>>>> > > My query is as follows: (oldTagName and newTagName are strings, as
>>>>> is
>>>>> > > the list trying to be modified)
On Tuesday, 24 July 2012, Jon Wynveen wrote:
> I found that I had updated my version of RavenDB.Database, but not
> RavenDB.Client. Once I did that it compiled (using the single
> AdvancedPatchRequest, not an array). But now when I try to run it, I'm
> getting this error:
> Url: "/bulk_docs"
>>> System.ArgumentException: Batching only supports PUT, PATCH and DELETE.
>> at Raven.Database.Data.CommandDataFactory.CreateCommand(RavenJObject
>>> jsonCommand, TransactionInformation transactionInformation) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Data\CommandDataFactory.cs:line 53
>> at
>>> Raven.Database.Server.Responders.DocumentBatch.<>c__DisplayClassa.<Batch>b_ _5(RavenJObject
>>> jsonCommand) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>>> 76
>> at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
>> at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
>> at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
>> at Raven.Database.Server.Responders.DocumentBatch.Batch(IHttpContext
>>> context) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>>> 75
>> at Raven.Database.Server.Responders.DocumentBatch.Respond(IHttpContext
>>> context) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>>> 38
>> at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx)
>>> in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 550
>> at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext
>>> ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line
>>> 316
> For clarity, here is my code as it stands now:
> RavenSession.Advanced.DocumentStore.DatabaseCommands.Patch("roles/1", new
>> AdvancedPatchRequest
> {
> Script
>> = "this.Permissions.Remove(perm);",
> Values
>> = {{"perm", "Read"}}
>> });
> On Tue, Jul 24, 2012 at 4:11 AM, Matt Warren <mattd...@gmail.com> wrote:
> You need to do this:
> RavenSession.Advanced.**DocumentStore.**DatabaseCommands.Patch("roles/**1", new
> AdvancedPatchRequest
> On Monday, 23 July 2012 22:36:49 UTC+1, Jon Wynveen wrote:
> I updated to the latest unstable just now (2042) and tried that code, but
> it doesn't compile. It can't convert from AdvancedPatchRequest to
> PatchRequest.
> On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com> wrote:
> I'm trying to do something similar using code from Oren above, but it
> doesn't seem to be working. I have Roles documents that have a Permissions
> array, and I'm trying to remove a permission from all users.
> An example role document:
> {
> "Name": "LC Administrator",
> "Permissions": [
> "Read",
> "Write",
> "Delete",
> "ViewPerformanceDiagnostics",
> "PreviewEmailsInBrowser",
> "ManageUsers"
On Tue, Jul 24, 2012 at 12:38 PM, Jon Wynveen <jonwynv...@gmail.com> wrote:
> I found that I had updated my version of RavenDB.Database, but not
> RavenDB.Client. Once I did that it compiled (using the single
> AdvancedPatchRequest, not an array). But now when I try to run it, I'm
> getting this error:
> Url: "/bulk_docs"
>>> System.ArgumentException: Batching only supports PUT, PATCH and DELETE.
>> at Raven.Database.Data.CommandDataFactory.CreateCommand(RavenJObject
>>> jsonCommand, TransactionInformation transactionInformation) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Data\CommandDataFactory.cs:line 53
>> at
>>> Raven.Database.Server.Responders.DocumentBatch.<>c__DisplayClassa.<Batch>b_ _5(RavenJObject
>>> jsonCommand) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>>> 76
>> at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
>> at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
>> at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
>> at Raven.Database.Server.Responders.DocumentBatch.Batch(IHttpContext
>>> context) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>>> 75
>> at Raven.Database.Server.Responders.DocumentBatch.Respond(IHttpContext
>>> context) in
>>> c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs: line
>>> 38
>> at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx)
>>> in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 550
>> at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext
>>> ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line
>>> 316
> For clarity, here is my code as it stands now:
> RavenSession.Advanced.DocumentStore.DatabaseCommands.Patch("roles/1", new
>> AdvancedPatchRequest
> {
> Script
>> = "this.Permissions.Remove(perm);",
> Values
>> = {{"perm", "Read"}}
>> });
> On Tue, Jul 24, 2012 at 4:11 AM, Matt Warren <mattd...@gmail.com> wrote:
>> You need to do this:
>> RavenSession.Advanced.**DocumentStore.**DatabaseCommands.Patch("roles/**1", new
>> AdvancedPatchRequest
>> On Monday, 23 July 2012 22:36:49 UTC+1, Jon Wynveen wrote:
>>> I updated to the latest unstable just now (2042) and tried that code,
>>> but it doesn't compile. It can't convert from AdvancedPatchRequest to
>>> PatchRequest.
>>> RavenSession.Advanced.**DocumentStore.**DatabaseCommands.Patch("roles/**1",
>>> new PatchRequest[]{
>>> new AdvancedPatchRequest
>>> On Saturday, July 21, 2012 3:01:51 AM UTC-5, Oren Eini wrote:
>>>> Hm,
>>>> The code assumes that if you are going to modify arrays, they are going
>>>> to be arrays of objects.
>>>> You can't do that using the Patch API.
>>>> If you can use the new unstable, this becomes:
>>>> On Thu, Jul 19, 2012 at 7:33 PM, Jon Wynveen <jonwynv...@gmail.com>wrote:
>>>>> I'm trying to do something similar using code from Oren above, but it
>>>>> doesn't seem to be working. I have Roles documents that have a Permissions
>>>>> array, and I'm trying to remove a permission from all users.
>>>>> I'm trying to remove the "Read" value with this code. It doesn't error
>>>>> or anything, it just doesn't seem to be removing that value at all.
>>>>> RavenSession.Advanced.**DocumentStore.DatabaseCommands
>>>>> .PutIndex("Roles/All",
>>>>> new IndexDefinitionBuilder<Role>
>>>>> {
>>>>> Map = roles => from role in roles
>>>>> select new {role.Name, role.Permissions, role.IsDeleted}
>>>>> });
>>>>> RavenSession.Advanced.**DocumentStore.DatabaseCommands
>>>>> .UpdateByIndex("Roles/All",
>>>>> new IndexQuery{Query="IsDeleted:**false"},
>>>>> new[]
>>>>> {
>>>>> new PatchRequest
>>>>> {
>>>>> Name = "Permissions",
>>>>> Type = PatchCommandType.Modify,
>>>>> AllPositions = true,
>>>>> Nested =
>>>>> new[]
>>>>> {
>>>>> new PatchRequest
>>>>> {
>>>>> Type = PatchCommandType.Remove,
>>>>> Value = "Read"
>>>>> }
>>>>> }
>>>>> }
>>>>> }, true);
>>>>> This is my first attempt at a patch like this, so I'm not sure if I'm
>>>>> doing anything wrong in here or if the syntax has changed since this
>>>>> original post.
>>>>> On Wednesday, April 13, 2011 8:34:07 AM UTC-5, Mike Sopinka wrote:
>>>>>> Since "Notes" was a list, it had a $type and $values when I looked at
>>>>>> the document in the web interface. So instead of setting the "Name"
>>>>>> to "Notes" in the nested patching, I set it to $values, and this did
>>>>>> the trick. It's working as I'd like!
>>>>>> > On Mon, Apr 11, 2011 at 6:18 PM, Mike Sopinka <msopi...@gmail.com>
>>>>>> wrote:
>>>>>> > > Thank you very much, I'm on my way! The only issue I have is
>>>>>> that I'm
>>>>>> > > getting an exception that says: Unable to cast object of type
>>>>>> > > 'Newtonsoft.Json.Linq.JValue' to type
>>>>>> 'Newtonsoft.Json.Linq.JObject'****.
>>>>>> > > Also, it is actually an IList<string>, not an array, but the JSON
>>>>>> was
>>>>>> > > still correct above.
>>>>>> > > My query is as follows: (oldTagName and newTagName are strings,
>>>>>> as is
>>>>>> > > the list trying to be modified)