【发布时间】:2016-04-07 09:59:48
【问题描述】:
在使用 arangoDB 时,是否有任何“简单”的方法可以避免上传重复的文档(带有自动生成的 _key)?
【问题讨论】:
标签: duplicates arangodb nosql
在使用 arangoDB 时,是否有任何“简单”的方法可以避免上传重复的文档(带有自动生成的 _key)?
【问题讨论】:
标签: duplicates arangodb nosql
执行此操作的 Arango 方法是 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
【讨论】:
{_id: '...', _key: '...', foo: true, bar: {...}} - 您将无法将索引放在顶级文档上,但即bar 中的所有内容或(作为附加参数监控)也@ 987654325@