1
arangoDBの使用中に重複したドキュメント(自動生成された_key)をアップロードするのを避けるための「簡単な」方法はありますか?arangoDBで重複を避ける方法
arangoDBの使用中に重複したドキュメント(自動生成された_key)をアップロードするのを避けるための「簡単な」方法はありますか?arangoDBで重複を避ける方法
これを行う方法は、to use a uniq hash indexです。しかし、それはそれの部分だけ、完全な文書の上に作成することができません:あなたが言ったこと
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
私は取得しない「それはそれの部分だけ、完全な文書の上に作成することができません」。私は私の文書が含むすべての属性のためのユニークなハッシュインデックスを作成しました。だから、既にデータベースにある1つのドキュメントと同じように、インデックス付き属性の値を持つドキュメントをアップロードしようとすると、表示されるエラーが発生します。そう、はい、私はハッシュインデックスは避けるのも簡単ですが、重複を避けるための最も簡単な方法だと思います。 – Dovi
は完全なドキュメントでは、{{id: '...'、_key: '...'、foo:true、bar:{...}} 'を意味していました。つまりトップレベルのドキュメントですが、 'bar'にあるものや(監視される追加パラメータとして)' foo' – dothebart