Root¶
The root of a BsonPath expression.
All BSON paths start at the root. For example, BsonPath["foo"] refers to the field "foo".
For more information, see BsonPath.
Properties¶
all¶
open override val all: BsonPath.PathOrSelector
Points to all children of a document.
-
The children of a
BsonArrayare its elements. -
The children of a
Bsondocument are the values of its fields.
Example¶
parent¶
Always returns null.
Functions¶
any¶
open fun any(vararg selectors: BsonPath.Selector): BsonPath
Allows specifying multiple selectors.
All elements that match a selector are returned, in the order of the selectors. For example, the path $[0, 3] returns the elements at index 0 and at index 3.
The same element may be returned multiple times if it matches multiple selectors.
The Selector type is obtained by the top-level functions on BsonPath.Root. Non-top-level paths are not allowed by the JSONPath specification.
Examples¶
-
BsonPath.any(BsonPath[0], BsonPath[3])returns["a", "d"] -
BsonPath.any(BsonPath.sliced(0, 2), BsonPath[5])returns["a", "b", "f"] -
BsonPath.any(BsonPath[0], BsonPath[0])returns["a", "a"]
findIn¶
@LowLevelApi
open override fun findIn(reader: BsonValueReader): Sequence<BsonValueReader>
Applies the filters described by this path on the reader.
Implementation notes¶
The reader is the root data. The path should recursively search by applying the parent's findIn first.
get¶
open operator override fun get(field: String): BsonPath.PathOrSelector
open operator override fun get(index: Int): BsonPath.PathOrSelector
parse¶
Deprecated¶
This function has been renamed to BsonPath(text).
Replace with
reversed¶
open override fun reversed(): BsonPath.PathOrSelector
Iterates a BsonArray in the reversed order, starting from the end.
If the node is not an array, nothing is returned.
This is a shorthand syntax for a slice of [::-1].
sliced¶
open override fun sliced(
start: Int?,
end: Int?,
step: Int
): BsonPath.PathOrSelector
Points to the elements of a BsonArray at the indices selected by start and end, with an optional step.
If the node is not an array, nothing is returned.
Elements can be iterated in the reversed order by having a start greater than the end and having a negative step.
If the smaller bound is null, it means "the first element of the array, inclusive". If the larger bound is null, it means "the last element of the array, inclusive".
Examples¶
-
BsonPath.sliced(1, 3)returns[1, 2] -
BsonPath.sliced(start = 5)returns[5, 6] -
BsonPath.sliced(1, 5, 2)returns[1, 3] -
BsonPath.sliced(5, 1, -2)returns[5, 3] -
BsonPath.sliced(step = -1)returns[6, 5, 4, 3, 2, 1, 0]
Parameters
-
start: The index at which the slice should start, inclusive.
-
end: The index at which the slice should end, exclusive.
-
step: How many elements should be skipped between found elements.
-
With
stepof 1, all elements are returned. -
With
stepof 2, every other element is returned. -
With
stepof 0, no elements are returned at all.
See also
BsonPath.reversed: Shorthand for reversing an array.
open override fun sliced(range: IntProgression): BsonPath.PathOrSelector
Points to the elements of a BsonArray at the indices selected by range.
If the node is not an array, nothing is returned.
To create an open-ended range, use the overload that accepts integers.
To reverse an array, see reversed.
Range normalization¶
When a range has a step, the IntProgression class can reduce the closing bound if the step does not reach it. For example, 1 .. 6 step 2 becomes 1 .. 5 step 2 because both ranges cover the values [1, 3, 5] and 6 could not have been included. This doesn't impact the outputs, but may impact the toString representation of this path.
Examples¶
BsonPath.sliced(1..<5) // $[1:5]: Items at indices 1 (inclusive) to 5 (exclusive)
BsonPath.sliced(1..5] // $[1:6]: Items at indices 1 (inclusive) to 5 (inclusive)
BsonPath.sliced(1..5 step 2) // $[1:6:2]: Items at indices 1 (inclusive) to 5 (inclusive), skipping every other item
BsonPath.sliced(5 downTo 1) // $[1:6:2]: Items at indices 1 (inclusive) to 5 (inclusive), in reverse order
See also
BsonPath.reversed: Shorthand to reverse an array.