mirror of https://gitee.com/bigwinds/arangodb
Exchanged verbinclude with Arangosh for bett examples in gitbook
This commit is contained in:
parent
eec6012318
commit
3eae1a4751
|
@ -1,98 +1,29 @@
|
|||
!CHAPTER Sequential Access and Cursors
|
||||
|
||||
`cursor.hasNext()`
|
||||
!SUBSECTION Has Next
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock cursorHasNext
|
||||
|
||||
The hasNext operator returns true, then the cursor still has documents. In this case the next document can be accessed using the next operator, which will advance the cursor.
|
||||
!SUBSECTION Next
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock cursorNext
|
||||
|
||||
*Examples*
|
||||
!SUBSECTION Set Batch size
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock cursorSetBatchSize
|
||||
|
||||
arango> var a = db.five.all();
|
||||
arango> while (a.hasNext()) print(a.next());
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 }
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 }
|
||||
{ "_id" : "five/1863832", "_key" : "1863832", "_rev" : "1863832", "doc" : 4 }
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 }
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
||||
!SUBSECTION Get Batch size
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock cursorGetBatchSize
|
||||
|
||||
`cursor.next()`
|
||||
!SUBSECTION Execute Query
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock queryExecute
|
||||
|
||||
If the hasNext operator returns true, then the underlying cursor of the simple query still has documents. In this case the next document can be accessed using the next operator, which will advance the underlying cursor. If you use next on an exhausted cursor, then undefined is returned.
|
||||
!SUBSECTION Dispose
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock cursorDispose
|
||||
|
||||
*Examples*
|
||||
|
||||
arango> db.five.all().next();
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 }
|
||||
|
||||
cursor.setBatchSize( number)
|
||||
Sets the batch size for queries. The batch size determines how many results are at most transferred from the server to the client in one chunk.
|
||||
|
||||
|
||||
cursor.getBatchSize()
|
||||
Returns the batch size for queries. If the returned value is undefined, the server will determine a sensible batch size for any following requests.
|
||||
|
||||
|
||||
query.execute( batchSize)
|
||||
Executes a simple query. If the optional batchSize value is specified, the server will return at most batchSize values in one roundtrip. The batchSize cannot be adjusted after the query is first executed.
|
||||
|
||||
Note that there is no need to explicitly call the execute method if another means of fetching the query results is chosen. The following two approaches lead to the same result:
|
||||
|
||||
result = db.users.all().toArray();
|
||||
q = db.users.all(); q.execute(); result = [ ]; while (q.hasNext()) { result.push(q.next()); }
|
||||
The following two alternatives both use a batchSize and return the same result:
|
||||
|
||||
q = db.users.all(); q.setBatchSize(20); q.execute(); while (q.hasNext()) { print(q.next()); }
|
||||
q = db.users.all(); q.execute(20); while (q.hasNext()) { print(q.next()); }
|
||||
|
||||
cursor.dispose()
|
||||
If you are no longer interested in any further results, you should call dispose in order to free any resources associated with the cursor. After calling dispose you can no longer access the cursor.
|
||||
|
||||
|
||||
cursor.count()
|
||||
The count operator counts the number of document in the result set and returns that number. The count operator ignores any limits and returns the total number of documents found.
|
||||
|
||||
Note
|
||||
Not all simple queries support counting. In this case null is returned.
|
||||
cursor.count(true)
|
||||
If the result set was limited by the limit operator or documents were skiped using the skip operator, the count operator with argument true will use the number of elements in the final result set - after applying limit and skip.
|
||||
|
||||
Note
|
||||
Not all simple queries support counting. In this case null is returned.
|
||||
Examples
|
||||
|
||||
Ignore any limit:
|
||||
|
||||
arango> db.five.all().limit(2).count();
|
||||
5
|
||||
Counting any limit or skip:
|
||||
|
||||
arango> db.five.all().limit(2).count(true);
|
||||
2
|
||||
|
||||
<!--
|
||||
@anchor SimpleQueryHasNext
|
||||
@copydetails JSF_SimpleQuery_prototype_hasNext
|
||||
|
||||
@CLEARPAGE
|
||||
@anchor SimpleQueryNext
|
||||
@copydetails JSF_SimpleQuery_prototype_next
|
||||
|
||||
@CLEARPAGE
|
||||
@anchor SimpleQuerySetBatchSize
|
||||
@copydetails JSF_SimpleQuery_prototype_setBatchSize
|
||||
|
||||
@CLEARPAGE
|
||||
@anchor SimpleQueryGetBatchSize
|
||||
@copydetails JSF_SimpleQuery_prototype_getBatchSize
|
||||
|
||||
@CLEARPAGE
|
||||
@anchor SimpleQueryExecute
|
||||
@copydetails JSF_SimpleQuery_prototype_execute
|
||||
|
||||
@CLEARPAGE
|
||||
@anchor SimpleQueryDispose
|
||||
@copydetails JSF_SimpleQuery_prototype_dispose
|
||||
|
||||
@CLEARPAGE
|
||||
@anchor SimpleQueryCount
|
||||
@copydetails JSF_SimpleQuery_prototype_count
|
||||
-->
|
||||
!SUBSECTION Count
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock cursorCount
|
|
@ -1,7 +1,7 @@
|
|||
!CHAPTER Modification Queries
|
||||
|
||||
ArangoDB also allows removing, replacing, and updating documents based
|
||||
on an example document. Every document in the collection will be
|
||||
on an example document. Every document in the collection will be
|
||||
compared against the specified example document and be deleted/replaced/
|
||||
updated if all attributes match.
|
||||
|
||||
|
@ -11,55 +11,8 @@ modify lots of documents in a collection.
|
|||
All methods can optionally be restricted to a specific number of operations.
|
||||
However, if a limit is specific but is less than the number of matches, it
|
||||
will be undefined which of the matching documents will get removed/modified.
|
||||
|
||||
!SUBSUBSECTION Examples
|
||||
|
||||
arangod> db.content.removeByExample({ "domain": "de.celler" })
|
||||
|
||||
`collection.replaceByExample( example, newValue)`
|
||||
|
||||
Replaces all documents matching an example with a new document body. The entire document body of each document matching the example will be replaced with newValue. The document meta-attributes such as _id, _key, _from, _to will not be replaced.
|
||||
|
||||
`collection.replaceByExample( document, newValue, waitForSync)`
|
||||
|
||||
The optional waitForSync parameter can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync parameter can be used to force synchronisation of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection's default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronisation for collections that have a default waitForSync value of true.
|
||||
|
||||
`collection.replaceByExample( document, newValue, waitForSync, limit)`
|
||||
|
||||
The optional limit parameter can be used to restrict the number of replacements to the specified value. If limit is specified but less than the number of documents in the collection, it is undefined which documents are replaced.
|
||||
|
||||
!SUBSUBSECTION Examples
|
||||
|
||||
arangod> db.content.replaceByExample({ "domain": "de.celler" }, { "foo": "someValue }, false, 5)
|
||||
|
||||
`collection.updateByExample( example, newValue)`
|
||||
|
||||
Partially updates all documents matching an example with a new document body. Specific attributes in the document body of each document matching the example will be updated with the values from newValue. The document meta-attributes such as _id, _key, _from, _to cannot be updated.
|
||||
|
||||
`collection.updateByExample( document, newValue, keepNull, waitForSync)`
|
||||
|
||||
The optional keepNull parameter can be used to modify the behavior when handling null values. Normally, null values are stored in the database. By setting the keepNull parameter to false, this behavior can be changed so that all attributes in data with null values will be removed from the target document.
|
||||
|
||||
The optional waitForSync parameter can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync parameter can be used to force synchronisation of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection's default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronisation for collections that have a default waitForSync value of true.
|
||||
|
||||
`collection.updateByExample( document, newValue, keepNull, waitForSync, limit)`
|
||||
|
||||
The optional limit parameter can be used to restrict the number of updates to the specified value. If limit is specified but less than the number of documents in the collection, it is undefined which documents are updated.
|
||||
|
||||
!SUBSUBSECTION Examples
|
||||
|
||||
arangod> db.content.updateByExample({ "domain": "de.celler" }, { "foo": "someValue, "domain": null }, false)
|
||||
|
||||
|
||||
<!--
|
||||
@anchor SimpleQueryRemoveByExample
|
||||
@copydetails JSF_ArangoCollection_prototype_removeByExample
|
||||
|
||||
@anchor SimpleQueryReplaceByExample
|
||||
@copydetails JSF_ArangoCollection_prototype_replaceByExample
|
||||
|
||||
@anchor SimpleQueryUpdateByExample
|
||||
@copydetails JSF_ArangoCollection_prototype_updateByExample
|
||||
|
||||
@BNAVIGATE_SimpleQueries
|
||||
-->
|
||||
[Remove by Example](../Documents/DocumentMethods.html#remove_by_example),
|
||||
[Replace by Example](../Documents/DocumentMethods.html#replace_by_example) and
|
||||
[Update by Example](../Documents/DocumentMethods.html#update_by_example)
|
||||
are described with examples in the subchapter
|
||||
[Collection Methods](../Documents/DocumentMethods.md).
|
|
@ -7,64 +7,15 @@ can the *skip* and *limit* operators. These operators work like LIMIT in
|
|||
MySQL.
|
||||
|
||||
*skip* used together with *limit* can be used to implement pagination.
|
||||
The @FN{skip} operator skips over the first n documents. So, in order to create
|
||||
The *skip* operator skips over the first n documents. So, in order to create
|
||||
result pages with 10 result documents per page, you can use `skip(n *
|
||||
10).limit(10)` to access the 10 documents on the n.th page. This result should
|
||||
be sorted, so that the pagination works in a predicable way.
|
||||
|
||||
!SUBSECTION Limit
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock queryLimit
|
||||
|
||||
`query.limit( number)`
|
||||
|
||||
Limits a result to the first number documents. Specifying a limit of 0 returns no documents at all. If you do not need a limit, just do not add the limit operator. The limit must be non-negative.
|
||||
|
||||
In general the input to limit should be sorted. Otherwise it will be unclear which documents are used in the result set.
|
||||
|
||||
*Examples*
|
||||
|
||||
arango> db.five.all().toArray();
|
||||
[
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 },
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 },
|
||||
{ "_id" : "five/1863832", "_key" : "1863832", "_rev" : "1863832", "doc" : 4 },
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 },
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
||||
]
|
||||
|
||||
arango> db.five.all().limit(2).toArray();
|
||||
[
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 },
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 }
|
||||
]
|
||||
|
||||
*query.skip( number)*
|
||||
|
||||
Skips the first number documents. If number is positive, then skip the number of documents. If number is negative, then the total amount N of documents must be known and the results starts at position (N + number).
|
||||
|
||||
In general the input to limit should be sorted. Otherwise it will be unclear which documents are used in the result set.
|
||||
|
||||
*Examples*
|
||||
|
||||
arango> db.five.all().toArray();
|
||||
[
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 },
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 },
|
||||
{ "_id" : "five/1863832", "_key" : "1863832", "_rev" : "1863832", "doc" : 4 },
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 },
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
||||
]
|
||||
|
||||
arango> db.five.all().skip(3).toArray();
|
||||
[
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 },
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
||||
]
|
||||
|
||||
|
||||
<!--
|
||||
@anchor SimpleQueryLimit
|
||||
@copydetails JSF_SimpleQuery_prototype_limit
|
||||
|
||||
@CLEARPAGE
|
||||
@anchor SimpleQuerySkip
|
||||
@copydetails JSF_SimpleQuery_prototype_skip
|
||||
-->
|
||||
!SUBSECTION Skip
|
||||
<!-- js/common/modules/org/arangodb/simple-query-common.js -->
|
||||
@startDocuBlock querySkip
|
|
@ -26,7 +26,8 @@
|
|||
{% if options.links.issues !== false && (options.links.issues || githubId) %}
|
||||
{% set _divider = true %}
|
||||
<li>
|
||||
<a href="{{ options.links.issues|default(githubHost+githubId+"/issues") }}" target="blank"class="issues-link">Have any questions?</a>
|
||||
<a href="{{ options.links.issues|default(githubHost+githubId+"/issues") }}" target="blank"class="issues-link">Have any Issues?</a>
|
||||
<a href="http://stackoverflow.com/questions/tagged/arangodb" target="blank">Have any questions?</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://www.arangodb.org/manuals/2/NewFeatures21.html" target="_blank">Whats New in this Version?</a>
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
arango> db.five.all().limit(2).count(true);
|
||||
2
|
|
@ -1,14 +0,0 @@
|
|||
arango> db.five.all().toArray();
|
||||
[
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 },
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 },
|
||||
{ "_id" : "five/1863832", "_key" : "1863832", "_rev" : "1863832", "doc" : 4 },
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 },
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
||||
]
|
||||
|
||||
arango> db.five.all().limit(2).toArray();
|
||||
[
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 },
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 }
|
||||
]
|
|
@ -1,2 +0,0 @@
|
|||
arango> db.five.all().next();
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 }
|
|
@ -1,7 +0,0 @@
|
|||
arango> var a = db.five.all();
|
||||
arango> while (a.hasNext()) print(a.next());
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 }
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 }
|
||||
{ "_id" : "five/1863832", "_key" : "1863832", "_rev" : "1863832", "doc" : 4 }
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 }
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
|
@ -1,14 +0,0 @@
|
|||
arango> db.five.all().toArray();
|
||||
[
|
||||
{ "_id" : "five/1798296", "_key" : "1798296", "_rev" : "1798296", "doc" : 3 },
|
||||
{ "_id" : "five/1732760", "_key" : "1732760", "_rev" : "1732760", "doc" : 2 },
|
||||
{ "_id" : "five/1863832", "_key" : "1863832", "_rev" : "1863832", "doc" : 4 },
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 },
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
||||
]
|
||||
|
||||
arango> db.five.all().skip(3).toArray();
|
||||
[
|
||||
{ "_id" : "five/1667224", "_key" : "1667224", "_rev" : "1667224", "doc" : 1 },
|
||||
{ "_id" : "five/1929368", "_key" : "1929368", "_rev" : "1929368", "doc" : 5 }
|
||||
]
|
|
@ -1,2 +0,0 @@
|
|||
arango> db.five.all().limit(2).count();
|
||||
5
|
|
@ -325,16 +325,16 @@ SimpleQuery.prototype.clone = function () {
|
|||
/// lead to the same result:
|
||||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{executeQuery}
|
||||
/// result = db.users.all().toArray();
|
||||
/// q = db.users.all(); q.execute(); result = [ ]; while (q.hasNext()) { result.push(q.next()); }
|
||||
/// result = db.users.all().toArray();
|
||||
/// q = db.users.all(); q.execute(); result = [ ]; while (q.hasNext()) { result.push(q.next()); }
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
///
|
||||
/// The following two alternatives both use a batchSize and return the same
|
||||
/// result:
|
||||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{executeQueryBatchSize}
|
||||
/// q = db.users.all(); q.setBatchSize(20); q.execute(); while (q.hasNext()) { print(q.next()); }
|
||||
/// q = db.users.all(); q.execute(20); while (q.hasNext()) { print(q.next()); }
|
||||
/// q = db.users.all(); q.setBatchSize(20); q.execute(); while (q.hasNext()) { print(q.next()); }
|
||||
/// q = db.users.all(); q.execute(20); while (q.hasNext()) { print(q.next()); }
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
///
|
||||
/// @endDocuBlock
|
||||
|
@ -370,8 +370,11 @@ SimpleQuery.prototype.execute = function () {
|
|||
/// unclear which documents are used in the result set.
|
||||
///
|
||||
/// @EXAMPLES
|
||||
///
|
||||
/// @verbinclude simple2
|
||||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{queryLimit}
|
||||
/// db.five.all().toArray();
|
||||
/// db.five.all().limit(2).toArray();
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
///
|
||||
/// @endDocuBlock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -393,7 +396,7 @@ SimpleQuery.prototype.limit = function (limit) {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief skip
|
||||
/// @startDocuBlock queySkip
|
||||
/// @startDocuBlock querySkip
|
||||
/// `query.skip(number)`
|
||||
///
|
||||
/// Skips the first *number* documents. If *number* is positive, then skip
|
||||
|
@ -406,7 +409,10 @@ SimpleQuery.prototype.limit = function (limit) {
|
|||
///
|
||||
/// @EXAMPLES
|
||||
///
|
||||
/// @verbinclude simple8
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{querySkip}
|
||||
/// db.five.all().toArray();
|
||||
/// db.five.all().skip(3).toArray();
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
///
|
||||
/// @endDocuBlock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -521,11 +527,15 @@ SimpleQuery.prototype.setBatchSize = function (value) {
|
|||
///
|
||||
/// Ignore any limit:
|
||||
///
|
||||
/// @verbinclude simple9
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{cursorCount}
|
||||
/// db.five.all().limit(2).count();
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
///
|
||||
/// Counting any limit or skip:
|
||||
///
|
||||
/// @verbinclude simple10
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{cursorCountLimit}
|
||||
/// db.five.all().limit(2).count(true);
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
///
|
||||
/// @endDocuBlock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -551,7 +561,10 @@ SimpleQuery.prototype.count = function (applyPagination) {
|
|||
///
|
||||
/// @EXAMPLES
|
||||
///
|
||||
/// @verbinclude simple7
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{cursorHasNext}
|
||||
/// var a = db.five.all();
|
||||
/// while (a.hasNext()) print(a.next());
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
/// @endDocuBlock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -574,7 +587,9 @@ SimpleQuery.prototype.hasNext = function () {
|
|||
///
|
||||
/// @EXAMPLES
|
||||
///
|
||||
/// @verbinclude simple5
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{cursorNext}
|
||||
/// db.five.all().next();
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
/// @endDocuBlock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
Loading…
Reference in New Issue