I'm currently struggling with something that should be trivial, and maybe it is, but I can't find a decent solution.
My problem originates with RavenDB default ID structure. Let's say we use the HiLo algorithm to create a person, we'll get our first document:
people/A-1
And the related collection "People" has now one member.
My problem is really simple: designing a normal RESTful method to get a single person:
GET people/:id
And calling it with the sample document ID, my call will become:
GET people/people/A-1
Which will obviously not work, since the slash character is the route separator character, but with RavenDB it's also part of the entity ID.
I've tried using a different separator (changing the conventions on my client code), so to get an ID like people#A-1
but this is not recognized by RavenDB Studio: if I try to "link" two documents together by their ID, only the standard format gets recognized. Also I couldn't find a way to set the convention on the database at server level, but only at client level.
This solution also feels like a dirty workaround, and I'm looking for the proper way of doing things.
I know I can use arbitrary IDs, like email addresses without any prefix, but this isn't feasible for all kinds of entities I'm going to store, natural key isn't an option in every scenario.
So I'm asking to anyone who is more experienced than me in using RavenDB. What's the proper way to address this problem?
You could pass only the 1-A
to the controller that recieve the request because PeopleController implies that you are going to work with People and then you can add the prefix to the id using RavenDB functions:
var collectionName = documentStore.Conventions.FindCollectionName(typeof(People));
var idPrefix = documentStore.Conventions.TransformTypeCollectionNameToDocumentIdPrefix(collectionName);
var id = idPrefix +"/"+ "1-A";
Otherwise you could change the id generation convention of that type
I have not used ravendb outside of toy projects, but when I read ayendes book, I thought this would be a problem. I see three possible ways to circumvent this:
I would use #1 I think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With