0

This question pertains to 4th version of RavenDb only. With previous versions we had an option to generate Identity Key for a collection viz.

 _documentStore.DatabaseCommands.NextIdentityFor(collectionName);

How do I do the same in RavenDb 4?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Abhay Naik
  • 410
  • 3
  • 15

1 Answers1

1

In RavenDB 4.0, this is now done as:

using (var shortTermSingleUse = JsonOperationContext.ShortTermSingleUse())
{
    var command = new NextIdentityForCommand("users");
    await store.GetRequestExecutor().ExecuteAsync(command, shortTermSingleUse);
}
Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • I had a question for distributed architecture. I know RavenDb4 now supports distributed architecture by design. Will the ids generated, by technique mentioned above be unique across databases? I have read about the allotment of range of Id(s) to every instance, so I am hoping answer is yes. – Abhay Naik Nov 14 '17 at 15:44
  • Yes, in this manner, this is done as a cluster operation and ensure that you have a value that is unique cluster wide for this database. – Ayende Rahien Nov 16 '17 at 07:24