Updating a property

133 views
Skip to first unread message

JanivZ

unread,
Apr 8, 2012, 7:39:35 AM4/8/12
to rav...@googlegroups.com
Hi all,
Im new to raven so i have a beginer question.

I have a set of document Id's on the server side. After I've finished working on them I'd like to send an 'update' command to update a state property on all the documents in my document list.

What would be the right way to do this ? Batch multiple Patch commands  ? ( can i have an example ? ) or something else ? 

Thank you.

Oren Eini (Ayende Rahien)

unread,
Apr 8, 2012, 8:13:09 AM4/8/12
to rav...@googlegroups.com
The easiest is to load the entity and modify it. this is simplest, easiest to understand and more than likely to be the most performant option.

You can also use: 

JanivZ

unread,
Apr 8, 2012, 8:41:35 AM4/8/12
to rav...@googlegroups.com
Hi Oren and thanks for the quick reply.

Just another small question:
Returning the whole list of documents to the server requires the re-serialization of all of them ( which in turn causes the problems you resolved for me in this question - http://stackoverflow.com/questions/10030704/raven-db-documentstore-throws-out-of-memory-exception), and then 
sending them all over the wire. This seems like a lot of work when i already know the document Id's i want to update. 

I don't mind a 'more complicated - but more efficient' solution - as this is going to be high scale app that needs to be as efficient as possible. Perhaps there's another direction i could try ? 

Thanks again !


On Sunday, 8 April 2012 15:13:09 UTC+3, Oren Eini wrote:
The easiest is to load the entity and modify it. this is simplest, easiest to understand and more than likely to be the most performant option.

You can also use: 

Oren Eini (Ayende Rahien)

unread,
Apr 8, 2012, 8:45:17 AM4/8/12
to rav...@googlegroups.com
You need to make sure that you send all of the patch command in the same Batch, not as inidividual Patch calls.

JanivZ

unread,
Apr 8, 2012, 8:50:10 AM4/8/12
to rav...@googlegroups.com
Thank you very much,

I'll give it a go. 

JanivZ

unread,
Apr 8, 2012, 9:33:39 AM4/8/12
to rav...@googlegroups.com
Something like this i guess ? 

        internal void Patch()
        {
            List<string> docIds = new List<string>() { "596548a7-61ef-4465-95bc-b651079f4888""cbbca8d5-be45-4e0d-91cf-f4129e13e65e" };
            using (var session = _documentStore.OpenSession())
            {
                session.Advanced.DatabaseCommands.Batch(GenerateCommands(docIds));
            }
        }

        private List<ICommandData> GenerateCommands(List<string> docIds )
        {
            List<ICommandData> retList = new List<ICommandData>();
 
            foreach (var item in docIds)
            {
                retList.Add(new PatchCommandData()
                {
                    Key = item,
                    Patches = new[] { new  Raven.Abstractions.Data.PatchRequest () {
                    Name = "Processed",
                    Type = Raven.Abstractions.Data.PatchCommandType.Set,
                    Value = new RavenJValue(true)
                }}});
            }
            
            return retList;
        }


Oren Eini (Ayende Rahien)

unread,
Apr 8, 2012, 10:21:29 AM4/8/12
to rav...@googlegroups.com
Yes

JanivZ

unread,
Apr 9, 2012, 3:04:32 AM4/9/12
to rav...@googlegroups.com
thx !


On Sunday, 8 April 2012 17:21:29 UTC+3, Oren Eini wrote:
Yes
Reply all
Reply to author
Forward
0 new messages