ra0o0f / arangoclient.net

ArangoDB .NET Client with LINQ support
Apache License 2.0
99 stars 37 forks source link

Custom Index #120

Closed imtrobin closed 5 years ago

imtrobin commented 5 years ago

Hi, is there a way to support custom index instead of _key? In more advanced cases, e.g for creating an authentication system using email, I would not be using the email as the key as I would allow the user to change email in future.

I can create an skiplist index on Email, so I can pass that in, but in the current form, just supporting _key, it means I have to do a search in db to get the _key first.

ra0o0f commented 5 years ago

@imtrobin if you mean composite primary key, then arangodb has not one. either you should somehow concatenate attributes to build _key attribute, or use a unique hash index on multiple attributes. which i think the later one is better in most cases

imtrobin commented 5 years ago

I don't think I can use either alternative, because the _key must be immutable. For example, the email can be changed so then, that would change the _key too on hash if its bult from attributes. So I would still have to lookup the db to find the _key from the email.

ra0o0f commented 5 years ago

_key is immutable and cant be changed after document is created, why unique hash index wont work for you?

{
  "_key":"3412342",
  // unique hash index on email attribute
  "email":"some@mail.com"
}
imtrobin commented 5 years ago

It will work, but as an example, I have to get the _key first. E.g to update a user, the user is gonna pass me his email username, not _key, so I will need to

ra0o0f commented 5 years ago

@imtrobin you can also update(upsert/insert/remove) a document with a filter expression and not retrieve it from database

https://github.com/ra0o0f/arangoclient.net/blob/master/src/ArangoDB.Client.Examples/Linq/ModificationQuery.cs

https://docs.arangodb.com/3.4/AQL/Operations/Update.html

imtrobin commented 5 years ago

I did it with an index using ByExample. The examples still requires the key.