mirror of https://gitee.com/bigwinds/arangodb
removeByExample sharded
This commit is contained in:
parent
b65637e924
commit
8d1ac573a6
|
@ -1,5 +1,5 @@
|
||||||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
|
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
|
||||||
/*global require, exports */
|
/*global ArangoClusterComm, ArangoClusterInfo, require, exports */
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief ArangoCollection
|
/// @brief ArangoCollection
|
||||||
|
@ -233,7 +233,7 @@ ArangoCollection.prototype.any = function () {
|
||||||
dbName,
|
dbName,
|
||||||
"/_api/simple/any",
|
"/_api/simple/any",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
collection: shard,
|
collection: shard
|
||||||
}),
|
}),
|
||||||
{ },
|
{ },
|
||||||
options);
|
options);
|
||||||
|
@ -304,13 +304,50 @@ ArangoCollection.prototype.firstExample = function (example) {
|
||||||
ArangoCollection.prototype.removeByExample = function (example,
|
ArangoCollection.prototype.removeByExample = function (example,
|
||||||
waitForSync,
|
waitForSync,
|
||||||
limit) {
|
limit) {
|
||||||
var deleted = 0;
|
|
||||||
var documents;
|
|
||||||
|
|
||||||
if (limit === 0) {
|
if (limit === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deleted = 0;
|
||||||
|
var documents;
|
||||||
|
var cluster = require("org/arangodb/cluster");
|
||||||
|
|
||||||
|
if (cluster.isCoordinator()) {
|
||||||
|
if (limit > 0) {
|
||||||
|
var err = new ArangoError();
|
||||||
|
err.errorNum = internal.errors.ERROR_NOT_IMPLEMENTED.code;
|
||||||
|
err.errorMessage = "limit not supported in clustered operation";
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dbName = require("internal").db._name();
|
||||||
|
var shards = cluster.shardList(dbName, this.name());
|
||||||
|
var coord = { coordTransactionID: ArangoClusterInfo.uniqid() };
|
||||||
|
var options = { coordTransactionID: coord.coordTransactionID, timeout: 360 };
|
||||||
|
|
||||||
|
shards.forEach(function (shard) {
|
||||||
|
ArangoClusterComm.asyncRequest("put",
|
||||||
|
"shard:" + shard,
|
||||||
|
dbName,
|
||||||
|
"/_api/simple/remove-by-example",
|
||||||
|
JSON.stringify({
|
||||||
|
collection: shard,
|
||||||
|
example: example,
|
||||||
|
waitForSync: waitForSync
|
||||||
|
}),
|
||||||
|
{ },
|
||||||
|
options);
|
||||||
|
});
|
||||||
|
|
||||||
|
var results = cluster.wait(coord, shards), i;
|
||||||
|
for (i = 0; i < results.length; ++i) {
|
||||||
|
var body = JSON.parse(results[i].body);
|
||||||
|
|
||||||
|
deleted += (body.deleted || 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
documents = this.byExample(example);
|
documents = this.byExample(example);
|
||||||
if (limit > 0) {
|
if (limit > 0) {
|
||||||
documents = documents.limit(limit);
|
documents = documents.limit(limit);
|
||||||
|
@ -323,6 +360,7 @@ ArangoCollection.prototype.removeByExample = function (example,
|
||||||
deleted++;
|
deleted++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return deleted;
|
return deleted;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue