1
0
Fork 0
arangodb/Documentation/DocuBlocks/collectionRange.md

1.3 KiB

@brief constructs a range query for a collection collection.range(attribute, left, right)

Returns all documents from a collection such that the attribute is greater or equal than left and strictly less than right.

You can use toArray, next, or hasNext to access the result. The result can be limited using the skip and limit operator.

An attribute name of the form a.b is interpreted as attribute path, not as attribute.

For range queries it is required that a skiplist index is present for the queried attribute. If no skiplist index is present on the attribute, an error will be thrown.

Note: the range simple query function is deprecated as of ArangoDB 2.6. The function may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection within a specific range is to use an AQL query as follows:

FOR doc IN @@collection 
  FILTER doc.value >= @left && doc.value < @right 
  LIMIT @skip, @limit 
  RETURN doc

@EXAMPLES

Use toArray to get all documents at once:

@EXAMPLE_ARANGOSH_OUTPUT{005_collectionRange} ~ db._create("old"); db.old.ensureIndex({ type: "skiplist", fields: [ "age" ] }); db.old.save({ age: 15 }); db.old.save({ age: 25 }); db.old.save({ age: 30 }); db.old.range("age", 10, 30).toArray(); ~ db._drop("old") @END_EXAMPLE_ARANGOSH_OUTPUT