Search code examples
arangodbunique-constraintunique-index

How to properly update an ArangoDB document with unique index field?


I have the following schema for users table:

   name: string
   emails: [string] // unique index

The index is created in the following way (in go language):

usersCollection.EnsureHashIndex(
    ctx, 
    []string{"emails[*]"}, 
    driver.EnsureHashIndexOptions{Unique: true, Sparse: true})

Let's say I have the following user in the DB:

{_key: "1", name: "A", emails: ["[email protected]"]}

Adding an email using the following command in arangosh returns an error:

> db.users.update("1", {emails: ["[email protected]", "[email protected]"]})
JavaScript exception in file '/usr/share/arangodb3/js/client/modules/@arangodb/arangosh.js' at 99,7: ArangoError 1210: unique constraint violated - in index 442818 of type rocksdb-hash over ["emails[*]"]; conflicting key: 1

Using replace returns similar error.

How can I properly add an email to the given user?


Solution

  • Apparently this is a bug in ArangoDB and will be solved later on:

    https://github.com/arangodb/arangodb/issues/8359