Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Replace string value in array
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  17 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike Sopinka  
View profile  
 More options Apr 11 2011, 9:27 am
From: Mike Sopinka <msopi...@gmail.com>
Date: Mon, 11 Apr 2011 06:27:19 -0700 (PDT)
Local: Mon, Apr 11 2011 9:27 am
Subject: Replace string value in array
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:

{
    "Id": 1,
    "Comment":
    {
         "Notes": [ "old", "wpf", "c#" ]
    }

}

And I want to do something like:
UPDATE documents
SET value = "new"
WHERE Notes CONTAINS "old"

So the resulting document would be:

{
    "Id": 1,
    "Comment":
    {
         "Notes": [ "new", "wpf", "c#" ]
    }

}

And I'd want this done for all documents.  Is this possible with the
CLIENT API?

Let me know if I need to clarify anything confusing.

Thanks!

Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options Apr 11 2011, 9:34 am
From: Ayende Rahien <aye...@ayende.com>
Date: Mon, 11 Apr 2011 16:34:39 +0300
Local: Mon, Apr 11 2011 9:34 am
Subject: Re: [RavenDB] Replace string value in array

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"
 },


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Sopinka  
View profile  
 More options Apr 11 2011, 11:18 am
From: Mike Sopinka <msopi...@gmail.com>
Date: Mon, 11 Apr 2011 08:18:32 -0700 (PDT)
Local: Mon, Apr 11 2011 11:18 am
Subject: Re: Replace string value in array
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options Apr 12 2011, 9:21 am
From: Ayende Rahien <aye...@ayende.com>
Date: Tue, 12 Apr 2011 16:21:47 +0300
Local: Tues, Apr 12 2011 9:21 am
Subject: Re: [RavenDB] Re: Replace string value in array

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
);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Sopinka  
View profile  
 More options Apr 13 2011, 9:34 am
From: Mike Sopinka <msopi...@gmail.com>
Date: Wed, 13 Apr 2011 06:34:07 -0700 (PDT)
Local: Wed, Apr 13 2011 9:34 am
Subject: Re: Replace string value in array
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Wynveen  
View profile  
 More options Jul 19 2012, 12:33 pm
From: Jon Wynveen <jonwynv...@gmail.com>
Date: Thu, 19 Jul 2012 09:33:08 -0700 (PDT)
Local: Thurs, Jul 19 2012 12:33 pm
Subject: Re: Replace string value in array

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile  
 More options Jul 19 2012, 6:35 pm
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Fri, 20 Jul 2012 01:35:04 +0300
Local: Thurs, Jul 19 2012 6:35 pm
Subject: Re: [RavenDB] Re: Replace string value in array

Remove  AllPositions = true,

What happens then?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Wynveen  
View profile  
 More options Jul 20 2012, 9:47 am
From: Jon Wynveen <jonwynv...@gmail.com>
Date: Fri, 20 Jul 2012 06:47:28 -0700 (PDT)
Local: Fri, Jul 20 2012 9:47 am
Subject: Re: [RavenDB] Re: Replace string value in array

When I remove the AllPositions, it gives me this error:

Cannot modify value from  'Permissions' because position element does not
exists or not an integer and allPositions is not set

But today even when I run it with AllPositions still in there, I'm getting
this error:

Url:
"/bulk_docs/Roles/All?query=IsDeleted%253Afalse&start=0&pageSize=128&aggreg ation=None&allowStale=True"

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile  
 More options Jul 21 2012, 4:01 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Sat, 21 Jul 2012 11:01:51 +0300
Local: Sat, Jul 21 2012 4:01 am
Subject: Re: [RavenDB] Re: Replace string value in array

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:

store.DatabaseCommands.Patch(docId, new AdvancedPatchRequest
{
   Script = "this.Permissions.Remove(perm);",
   Values = {{"perm", "Read"}}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Wynveen  
View profile  
 More options Jul 23 2012, 5:36 pm
From: Jon Wynveen <jonwynv...@gmail.com>
Date: Mon, 23 Jul 2012 14:36:49 -0700 (PDT)
Local: Mon, Jul 23 2012 5:36 pm
Subject: Re: [RavenDB] Re: Replace string value in array

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"}}
                                                                        }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Troy  
View profile  
 More options Jul 23 2012, 8:49 pm
From: Troy <tzar...@gmail.com>
Date: Mon, 23 Jul 2012 17:49:47 -0700 (PDT)
Local: Mon, Jul 23 2012 8:49 pm
Subject: Re: [RavenDB] Re: Replace string value in array

You may need to get the Nuget package Rx-Linq .. I think this is the one I
needed to make it compile..


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Troy  
View profile  
 More options Jul 23 2012, 8:50 pm
From: Troy <tzar...@gmail.com>
Date: Mon, 23 Jul 2012 17:50:43 -0700 (PDT)
Local: Mon, Jul 23 2012 8:50 pm
Subject: Re: [RavenDB] Re: Replace string value in array

Oops, disregard.. I needed that for the new Change API. Sorry.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Warren  
View profile  
 More options Jul 24 2012, 3:15 am
From: Matt Warren <mattd...@gmail.com>
Date: Tue, 24 Jul 2012 08:15:25 +0100
Local: Tues, Jul 24 2012 3:15 am
Subject: Re: [RavenDB] Re: Replace string value in array

There should be an overload of DatabaseCommand.Patch(..) that accepts and
AdvancedPatchRequest, do you have that available?

On 23 July 2012 22:36, Jon Wynveen <jonwynv...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Warren  
View profile  
 More options Jul 24 2012, 5:11 am
From: Matt Warren <mattd...@gmail.com>
Date: Tue, 24 Jul 2012 02:11:24 -0700 (PDT)
Local: Tues, Jul 24 2012 5:11 am
Subject: Re: [RavenDB] Re: Replace string value in array

You need to do this:

RavenSession.Advanced.DocumentStore.DatabaseCommands.Patch("roles/1", new
AdvancedPatchRequest
                                                                         {
                                                                         Script
= "this.Permissions.Remove(perm);",
                                                                         Values
= {{"perm", "Read"}}
                                                                         });

Just pass in an AdvancedPatchRequest directly.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Wynveen  
View profile  
 More options Jul 24 2012, 1:38 pm
From: Jon Wynveen <jonwynv...@gmail.com>
Date: Tue, 24 Jul 2012 12:38:16 -0500
Local: Tues, Jul 24 2012 1:38 pm
Subject: Re: [RavenDB] Re: Replace string value in array

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"

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"}}

                                                                        });

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Warren  
View profile   Translate to Translated (View Original)
 More options Jul 24 2012, 5:20 pm
From: Matt Warren <mattd...@gmail.com>
Date: Tue, 24 Jul 2012 22:20:29 +0100
Local: Tues, Jul 24 2012 5:20 pm
Subject: Re: [RavenDB] Replace string value in array

It looks like you have an old version of the ravendb server. Have you
updated the entire server to a new build?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kijana Woodard  
View profile  
 More options Jul 24 2012, 5:37 pm
From: Kijana Woodard <kijana.wood...@gmail.com>
Date: Tue, 24 Jul 2012 16:37:21 -0500
Local: Tues, Jul 24 2012 5:37 pm
Subject: Re: [RavenDB] Re: Replace string value in array

This happened to me last night. It turns out I got build 616 through NSB
and got this error accessing it with a 960 client.

Now, to figure out why 616 was bundled with NSB 3.2.6.......or how I lost
my mind and got into an old nsb folder.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »