[英]How to avoid duplicates in arangoDB
在使用arangoDB時,有沒有“簡單”的方法來避免上傳重復文檔(使用自動生成的_key)?
Arango這樣做的方法是使用uniq哈希索引 。 但是,無法在整個文檔中創建它,只能創建它的一部分:
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.