Change "_key" attribute name (or delete it as default). ArangoDB data models.

284 views
Skip to first unread message

Victor Caballero

unread,
Sep 20, 2017, 7:49:43 AM9/20/17
to ArangoDB
Hello,

I am new to arangodb and I've come up with two questions.

The first one is if it is possible to change the "_key" attribute name. I mean, my model has objects with an id attribute, which I would like to expose as a JSON abject with the attribute "id". I have made serializers for that purpose, which, in fact, have an "id" key. The problem is that when it comes to saving the object to the arangodb, it ends having to unique identifiers, namely "id" and "_key". Is it possible to rename or delete the "_key" attribute for all obejcts?

The second question that is maybe related to the first one is about arangodb data models (document model an graph model). Is it possible to have a mix of models where a document has a named relationship to another document in a different collection. As far as I have investigated, it is possible but, does the vertex id have to be in the "_key" attribute?

Thanks,

Víctor

Wilfried Gösgens

unread,
Sep 20, 2017, 8:16:53 AM9/20/17
to ArangoDB
Hi,
no, the `_key` attribute can't be changed.
However, you can add indices to any attributes of your documents to ensure the uniqueness:
https://docs.arangodb.com/3.2/Manual/Indexing/IndexBasics.html#hash-index
If you want to use only one attribute as the primary key, you will have to rename your `id` attribute to `_key` - maybe in the serialization code?

Regarding graphs, as explained at https://docs.arangodb.com/3.2/Manual/Graphs/ - vertices are referenced by their `_key` - via the `_to` and `_from` attributes in edge collections.

However, ArangoDB gives you lots of freedom how these documents look for the rest, and how they're related to documents in other collections.

Cheers,
Willi

Victor Caballero

unread,
Sep 20, 2017, 9:46:53 AM9/20/17
to ArangoDB
Thanks.



If you want to use only one attribute as the primary key, you will have to rename your `id` attribute to `_key` - maybe in the serialization code?

I know, that was what I wanted to avoid. The thing is that now I am forced to have two json serializers, one for the application clients and the other for arangodb. I don't think this code duplication is harmful but it adds extra work :P .
Reply all
Reply to author
Forward
0 new messages