Reputation: 159
We have a DotNet Core API (C#) on AWS with clustered RavenDB servers (5.23). When documents are created then the Id has a different format depending on the client. If using Swagger/Postman/xUnit Test then we get Id="person/1234-C". If a third party calls the endpoint then we get Id="Person/0000000000000001234-C". Note that the first character is lowercase in one and uppercase in the other. The person.Id (string) property is set to null before the entity is saved.
There is no custom configuration of the Id formats. The only convention set is MaxNumberOfRequestsPerSession. I've read the docs on Ids (Server Id/Identity) but I haven't seen anything useful.
Why is the Id format different? How can I ensure that it's always the correct format? Would a client and AWS in different countries with different languages (but same timezone) have any impact somehow?
Upvotes: 3
Views: 74
Reputation: 176
RanenDB id is case insensitive. But it doesn't change the case. If you set a specific id RavenDB will use it as is.
The short id ("person/1234-C") typically comes from Hilo If you use Hilo to generate the id you have multiple ways to control the prefix.
The long id ("Person/0000000000000001234-C") typically comes from the server To use server-side you store the document with a prefix like "Person/" (or "person/" and RavenDB keeps the case).
https://ravendb.net/docs/article-page/5.0/csharp/server/kb/document-identifier-generation https://ravendb.net/docs/article-page/4.2/faq/client-api/configuration/identifier-generation/global
https://github.com/ravendb/ravendb/discussions/13111
class TestObj
{
public string Id { get; set; }
}
class TestObj3
{
public string Id { get; set; }
}
class TestObj2
{
public string Id { get; set; }
public string Prop { get; set; }
}
[Fact]
public async Task TestCase()
{
using var store = GetDocumentStore(new Options
{
ModifyDocumentStore = s =>
{
s.Conventions.FindCollectionName = t => t == typeof(TestObj) ? t.Name.ToLower() : null;
s.Conventions.RegisterAsyncIdConvention<TestObj2>((s1, class2) => Task.FromResult($"testClass2/{class2.Prop}"));
}
});
using (var session = store.OpenAsyncSession())
{
var testObj = new TestObj();
await session.StoreAsync(testObj); // "testobj/1-A"
var testObj2 = new TestObj2{Prop = "Something"};
await session.StoreAsync(testObj2); // "testClass2/Something"
var testObj3 = new TestObj3();
await session.StoreAsync(testObj3); // "TestObj3s/1-A"
var testObj4 = new TestObj3();
await session.StoreAsync(testObj4, "TestObj/"); // "TestObj/0000000000000000006-A"
var testObj5 = new TestObj3();
await session.StoreAsync(testObj5, "testobj/"); // "TestObj/0000000000000000006-A"
await session.SaveChangesAsync();
}
}
Upvotes: 1
Reputation: 3839
Have you seen this article ?
Format Person/0000000000000001234-C
is generated by the server
See Server-Side ID
Format person/1234-C
can be generated by both the server & the client
See Hilo Algorithm
Upvotes: 1