Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update a document with unique index (constraints)? #8359

Closed
robert-zaremba opened this issue Mar 11, 2019 · 7 comments
Closed

How to update a document with unique index (constraints)? #8359

robert-zaremba opened this issue Mar 11, 2019 · 7 comments
Assignees
Labels
Milestone

Comments

@robert-zaremba
Copy link

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

My Environment

  • ArangoDB Version: 3.4.3
  • Storage Engine: RocksDB
  • Deployment Mode: Single Server
  • Infrastructure: localhost
  • Operating System: Fedora 29
  • Total RAM in your machine: 16GB
  • Disks in use: HDD
  • Used Package: official RPM

more details

I posted the whole question and problem on StackOverflow:
https://stackoverflow.com/questions/54916765/how-to-properly-update-an-arangodb-document-with-unique-index-field

@dothebart
Copy link
Contributor

Yes, you're right. This missbehaviour was introduced with ArangoDB3.4

@robert-zaremba
Copy link
Author

Will this be updated? When? What's the proper way to handle this now (update an object with unique constraints)?

@dothebart
Copy link
Contributor

dothebart commented Mar 11, 2019

yes, thats why I flagged it with 'bug'. The workaround should be clear from the stackoverflow issue? 3.4.4 won't contain a fix for this, its to late in the QA pipeline already. If its more convenient for your application, try to do this in a foxx-service meanwhile.

@dothebart
Copy link
Contributor

#8422 will fix this in 3.4 - if you want a fixed environment now, you may try to checkout the branch bug-fix-3.4/arrayindex-unique-update and compile your own arangod.

@maxkernbach
Copy link
Contributor

Hi @robert-zaremba,

version 3.4.5, which includes a fix for this issue, has just been released.
Could you please give it a try?

The latest release is available in the download section.

@maxkernbach
Copy link
Contributor

Closing this issue as fixed. Updating an object with unique constraints works in 3.4.5.

Working arangosh example:

Create collection:

db._create('usersCollection')
[ArangoCollection 106, "usersCollection" (type document, status loaded)]

Add unique index:


db.usersCollection.ensureIndex({ type: "hash", fields: [ "emails[*]" ], unique: true, sparse: true })
{ 
  "deduplicate" : true, 
  "fields" : [ 
    "emails[*]" 
  ], 
  "id" : "usersCollection/517", 
  "isNewlyCreated" : true, 
  "selectivityEstimate" : 1, 
  "sparse" : true, 
  "type" : "hash", 
  "unique" : true, 
  "code" : 201 
}

Create document entry:

db.usersCollection.save({_key: "1", name: "A", emails: ["aa@aa.aa"]})
{ 
  "_id" : "usersCollection/1", 
  "_key" : "1", 
  "_rev" : "_Yi26PIa---" 

Add email in the "emails" field:

db.usersCollection.update("1", {emails: ["aa@aa.aa", "aa2@aa.aa"]})
{ 
  "_id" : "usersCollection/1", 
  "_key" : "1", 
  "_rev" : "_Yi27SlW--_", 
  "_oldRev" : "_Yi26PIa---" 
}

Inspect collection:

db.usersCollection.toArray()
[ 
  { 
    "_key" : "1", 
    "_id" : "usersCollection/1", 
    "_rev" : "_Yi27SlW--_", 
    "name" : "A", 
    "emails" : [ 
      "aa@aa.aa", 
      "aa2@aa.aa" 
    ] 
  } 
]

@robert-zaremba
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants