Define operations in RavenDB

I read this article about ravendb-related activities, but it did not show me how to update a set of documents through C #. I would like to update the field in all documents that meet certain criteria. Or, to put it another way, I would like to take this C # and make it more efficient:

var session = db.GetSession(); foreach(var data in session.Query<Data>().Where(d => d.Color == "Red")) { data.Color = "Green"; session.Store(data); } session.SaveChanges(); 
+4
source share
1 answer

See http://ravendb.net/docs/2.5/faq/denormalized-updates

The first parameter is the name of the index you want to update. The second parameter is an index query, which allows you to specify a where clause. The query syntax is lucene syntax ( http://lucene.apache.org/java/2_4_0/queryparsersyntax.html ). The third parameter is the update clause. The fourth parameter is if you want obsolete results.

 documentStore.DatabaseCommands.UpdateByIndex("DataByColor", new IndexQuery { Query = "Color:red" }, new[] { new PatchRequest { Type = PatchCommandType.Set, Name = "Color", Value = "Green" } }, allowStale: false); 
+6
source

All Articles