mirror of https://gitee.com/bigwinds/arangodb
collection.any() sharded
This commit is contained in:
parent
7a8f2257cc
commit
51a58b7844
|
@ -1873,8 +1873,6 @@ static v8::Handle<v8::Value> JS_AnyQuery (v8::Arguments const& argv) {
|
|||
if (col == 0) {
|
||||
TRI_V8_EXCEPTION_INTERNAL(scope, "cannot extract collection");
|
||||
}
|
||||
|
||||
TRI_SHARDING_COLLECTION_NOT_YET_IMPLEMENTED(scope, col);
|
||||
|
||||
TRI_barrier_t* barrier = 0;
|
||||
TRI_doc_mptr_t document;
|
||||
|
@ -3117,7 +3115,7 @@ void TRI_InitV8Queries (v8::Handle<v8::Context> context) {
|
|||
rt = v8g->VocbaseColTempl;
|
||||
|
||||
TRI_AddMethodVocbase(rt, "ALL", JS_AllQuery);
|
||||
TRI_AddMethodVocbase(rt, "any", JS_AnyQuery);
|
||||
TRI_AddMethodVocbase(rt, "ANY", JS_AnyQuery);
|
||||
TRI_AddMethodVocbase(rt, "BY_CONDITION_BITARRAY", JS_ByConditionBitarray);
|
||||
TRI_AddMethodVocbase(rt, "BY_CONDITION_SKIPLIST", JS_ByConditionSkiplist);
|
||||
TRI_AddMethodVocbase(rt, "BY_EXAMPLE", JS_ByExampleQuery);
|
||||
|
|
|
@ -1085,6 +1085,7 @@ static v8::Handle<v8::Value> DocumentVocbaseCol_Coordinator (
|
|||
|
||||
// First get the initial data:
|
||||
string const dbname(collection->_dbName);
|
||||
// TODO: someone might rename the collection while we're reading its name...
|
||||
string const collname(collection->_name);
|
||||
|
||||
string key;
|
||||
|
|
|
@ -209,14 +209,58 @@ ArangoCollection.prototype.index = function (id) {
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns any document from a collection
|
||||
///
|
||||
/// @FUN{@FA{collection}.any()
|
||||
///
|
||||
/// Returns a random document from the collection or @LIT{null} if none exists.
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ArangoCollection.prototype.any = function () {
|
||||
var cluster = require("org/arangodb/cluster");
|
||||
|
||||
if (cluster.isCoordinator()) {
|
||||
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/any",
|
||||
JSON.stringify({
|
||||
collection: shard,
|
||||
}),
|
||||
{ },
|
||||
options);
|
||||
});
|
||||
|
||||
var results = cluster.wait(coord, shards), i;
|
||||
for (i = 0; i < results.length; ++i) {
|
||||
var body = JSON.parse(results[i].body);
|
||||
if (body.document !== null) {
|
||||
return body.document;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.ANY();
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructs a query-by-example for a collection
|
||||
///
|
||||
/// @FUN{@FA{collection}.firstExample(@FA{example})}
|
||||
///
|
||||
/// Returns the a document of a collection that match the specified example or
|
||||
/// @LIT{null}. The example must be specified as paths and values. See
|
||||
/// @FN{byExample} for details.
|
||||
/// Returns the first document of a collection that matches the specified
|
||||
/// example or @LIT{null}. The example must be specified as paths and values.
|
||||
/// See @FN{byExample} for details.
|
||||
///
|
||||
/// @FUN{@FA{collection}.firstExample(@FA{path1}, @FA{value1}, ...)}
|
||||
///
|
||||
|
@ -245,10 +289,9 @@ ArangoCollection.prototype.firstExample = function (example) {
|
|||
}
|
||||
}
|
||||
|
||||
var documents = simple.byExample(this, e, 0, 1);
|
||||
|
||||
if (0 < documents.documents.length) {
|
||||
return documents.documents[0];
|
||||
var documents = (new simple.SimpleQueryByExample(this, e)).limit(1).toArray();
|
||||
if (documents.length > 0) {
|
||||
return documents[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue