简体   繁体   English

如何避免arangoDB中的重复

[英]How to avoid duplicates in arangoDB

在使用arangoDB时,有没有“简单”的方法来避免上传重复文档(使用自动生成的_key)?

The Arango way of doing this is to use a uniq hash index . Arango这样做的方法是使用uniq哈希索引 However, it can't be created over the full document, only parts of it: 但是,无法在整个文档中创建它,只能创建它的一部分:

db._create("testuniq")
[ArangoCollection 25260888467, "testuniq" (type document, status loaded)]
arangosh [_system]> db.testuniq.ensureIndex({ type: "hash", fields:["uniqDocument", "uniqAttribute"], unique: true })
{ 
  "id" : "testuniq/25264886163", 
  "type" : "hash", 
  "fields" : [ 
    "uniqDocument", 
    "uniqAttribute" 
  ], 
  "selectivityEstimate" : 1, 
  "unique" : true, 
  "sparse" : false, 
  "isNewlyCreated" : true, 
  "code" : 201 
}
arangosh [_system]> db.testuniq.save({uniqDocument: {foo: "bar"}})
arangosh [_system]> db.testuniq.save({uniqDocument: {foo: "bar"}})
JavaScript exception in file 'js/client/modules/org/arangodb/arangosh.js' at 106,13: ArangoError 1210: cannot create document, unique constraint violated
!      throw error;
!            ^
stacktrace: ArangoError: cannot create document, unique constraint violated
    at Object.exports.checkRequestResult (js/client/modules/org/arangodb/arangosh.js:104:21)
    at ArangoCollection.save.ArangoCollection.insert (js/client/modules/org/arangodb/arango-collection.js:1014:12)
    at <shell command>:1:13
arangosh [_system]> db.testuniq.save({uniqAttribute: "bar"})
arangosh [_system]> db.testuniq.save({uniqAttribute: "bar"})
JavaScript exception in file 'js/client/modules/org/arangodb/arangosh.js' at 106,13: ArangoError 1210: cannot create document, unique constraint violated
!      throw error;
!            ^
stacktrace: ArangoError: cannot create document, unique constraint violated
    at Object.exports.checkRequestResult (js/client/modules/org/arangodb/arangosh.js:104:21)
    at ArangoCollection.save.ArangoCollection.insert (js/client/modules/org/arangodb/arango-collection.js:1014:12)
    at <shell command>:1:13

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM