Charlie B
Charlie B

Reputation: 35

In RavenDB can I retrieve all document Id's for a document type

My Scenario: I have a few thousand documents that I want alter (rename & add properties), I have written a a PatchRequest to alter the document but this takes a document Id.

I'm looking for a way to get a list of document Id's for all documents of a specific type, any ideas?

If possible I'd like to avoid retrieving the document from the server.

Upvotes: 2

Views: 549

Answers (1)

Judah Gabriel Himango
Judah Gabriel Himango

Reputation: 60011

I have written a PatchRequest to alter the document but this takes a document Id.

No, .Patch takes a document ID, not the PatchRequest.

Since you want to update a whole swath of documents, you'll want to use the .UpdateByIndex method:

documentStore.DatabaseCommands.UpdateByIndex("IndexName",
      new IndexQuery {Query = "Title:RavenDB"},
      new []
      {
         new PatchRequest
         {
            Type = PatchCommandType.Add,
            Name = "Comments",
            Value = "New automatic comment we added programmatically"
         }
      }, allowStale: false);

This will allow you to patch all documents matching an index. That index can be whatever you please.

For more information, see Set-Based Operations in the Raven docs.

Upvotes: 2

Related Questions