Readonly
[unscopables]An Object whose truthy properties are properties that are excluded from the 'with' environment bindings of the associated objects.
Optional
Readonly
[unscopables]?: booleanIs an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
length?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
The number of values.
An Error as the length property cannot be assigned.
Whether null
is a valid value for the collection.
Whether null
is a valid value for the collection.
Name of the type of items.
The name of the type of values.
An iterator that iterates over all the values in the collection.
Add a listener callback
which will be called when a live collection instance changes.
A function to be called when changes occur.
Optional
keyPaths: string | string[]Indicates a lower bound on the changes relevant for the listener. This is a lower bound, since if multiple listeners are added (each with their own keyPaths
) the union of these key-paths will determine the changes that are considered relevant for all listeners registered on the collection. In other words: A listener might fire more than the key-paths specify, if other listeners with different key-paths are present.
deletions and
oldModificationsreport the indices in the collection before the change happened, while
insertionsand
newModificationsreport the indices into the new version of the collection. @throws A {@link TypeAssertionError} if
callback is not a function. @example wines.addListener((collection, changes) => { // collection === wines console.log(
${changes.insertions.length} insertions); console.log(
${changes.oldModifications.length} oldModifications); console.log(
${changes.newModifications.length} newModifications); console.log(
${changes.deletions.length} deletions); console.log(
new size of collection: ${collection.length}); }); @example wines.addListener((collection, changes) => { console.log("A wine's brand might have changed"); }, ["brand"]); @note Adding the listener is an asynchronous operation, so the callback is invoked the first time to notify the caller when the listener has been added. Thus, when the callback is invoked the first time it will contain empty arrays for each property in the
changes` object.
The element at the given index in the array; undefined
if there is no element at the given index.
index - The index of the element to return from the array. If the index is a negative number, the element at array.length + index
is returned.
Computes the average of the values in the collection or of the given
property among all the objects in the collection, or undefined
if the collection
is empty.
Only supported for int, float and double properties. null
values are
ignored entirely by this method and will not be factored into the average.
Optional
property: stringFor a collection of objects, the property to take the average of.
The sum.
An Error if no property with the name exists or if property is not numeric.
Rest
...items: ConcatArray<T>[]Arrays and/or values to concatenate into a new array.
A new array with the results of calling a provided function on every element in this array.
Rest
...items: (T | ConcatArray<T>)[]Arrays and/or values to concatenate into a new array.
A new array with the results of calling a provided function on every element in this array.
true
if the callback function returns a truthy value for every collection element; otherwise, false
.
predicate - A function to test for each element.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection every
was called upon.
thisArg - An object to which the this
keyword can refer in the predicate function. If thisArg
is omitted, undefined
is used as the this
value.
Optional
thisArg: anytrue
if the callback function returns a truthy value for every collection element; otherwise, false
.
predicate - A function to test for each element.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection every
was called upon.
thisArg - An object to which the this
keyword can refer in the predicate function. If thisArg
is omitted, undefined
is used as the this
value.
A new array containing the elements of the collection for which the predicate
function returned true
.
predicate - A function that accepts up to three arguments. The filter
method calls the predicate
function one time for each element in the collection.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection filter
was called upon.
thisArg - An object to which the this
keyword can refer in the predicate
function. If thisArg
is omitted, undefined
is used as the this
value.
Optional
thisArg: anyA new array containing the elements of the collection for which the predicate
function returned true
.
predicate - A function that accepts up to three arguments. The filter
method calls the predicate
function one time for each element in the collection.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection filter
was called upon.
thisArg - An object to which the this
keyword can refer in the predicate
function. If thisArg
is omitted, undefined
is used as the this
value.
Returns new Results that represent this collection being filtered by the provided query.
Query used to filter objects from the collection.
Rest
...args: unknown[]Each subsequent argument is used by the placeholders
(e.g. $0
, $1
, $2
, …) in the query.
Results filtered according to the provided query.
An Error if the query or any other argument passed into this method is invalid.
This is currently only supported for collections of Realm Objects.
let merlots = wines.filtered('variety == "Merlot" && vintage <= $0', maxYear);
The value of the first element in the array that satisfies the provided testing function. Otherwise, undefined
is returned.
predicate - A function that accepts up to three arguments. The find
method calls the predicate
function one time for each element in the collection.
predicate.value - The value of the element.
predicate.index - The index of the element.
predicate.obj - The object being traversed.
thisArg - An object to which the this
keyword can refer in the predicate
function. If thisArg
is omitted, undefined
is used as the this
value.
Optional
thisArg: anyThe value of the first element in the array that satisfies the provided testing function. Otherwise, undefined
is returned.
predicate - A function that accepts up to three arguments. The find
method calls the predicate
function one time for each element in the collection.
predicate.value - The value of the element.
predicate.index - The index of the element.
predicate.obj - The object being traversed.
thisArg - An object to which the this
keyword can refer in the predicate
function. If thisArg
is omitted, undefined
is used as the this
value.
Optional
thisArg: anyThe index of the first element in the array that satisfies the provided testing function. Otherwise, -1 is returned.
predicate - A function that accepts up to three arguments. The findIndex
method calls the predicate
function one time for each element in the collection.
predicate.value - The value of the element.
predicate.index - The index of the element.
predicate.obj - The object being traversed.
thisArg - An object to which the this
keyword can refer in the predicate
function. If thisArg
is omitted, undefined
is used as the this
value.
A new array with each element being the result of the callback function and flattened to a depth of 1.
callback - Function that produces an element of the new Array, taking three arguments:
callback.currentValue - The current element being processed in the array.
callback.index - The index of the current element being processed in the array.
callback.array - The array flatMap
was called upon.
thisArg - Value to use as this when executing callback.
Optional
thisArg: anycallbackfn - A function that accepts up to three arguments. forEach
calls the callbackfn function one time for each element in the collection.
callbackfn.value - The current element being processed in the collection.
callbackfn.index - The index of the current element being processed in the collection.
callbackfn.array - The collection forEach
was called upon.
thisArg - An object to which the this
keyword can refer in the callbackfn
function. If thisArg
is omitted, undefined
is used as the this
value.
Optional
fromIndex: numbertrue
if the searchElement
is found in the array; otherwise, false
.
searchElement - The element to search for.
fromIndex - The position in this array at which to begin searching for searchElement
. A negative value searches from the index of array.length + fromIndex by asc.
fromIndex
is currently not supported. So all searches start at index 0.
Optional
fromIndex: numberThe first index at which a given element can be found in the collection, or -1 if it is not present.
searchElement - Element to locate in the collection.
fromIndex - The collection index at which to begin the search. If omitted, the search starts at index 0.
fromIndex
is currently not supported. So all searches start at index 0.
Optional
fromIndex: numberThe last index at which a given element can be found in the collection, or -1 if it is not present. The collection is searched backwards, starting at fromIndex
.
searchElement - Element to locate in the collection.
fromIndex - The collection index at which to begin the search. If omitted, the search starts at the last index.
A new array containing the results of calling the callbackfn
function on each element in the collection.
callbackfn - A function that accepts up to three arguments. The map
method calls the callbackfn
function one time for each element in the collection.
callbackfn.value - The current element being processed in the collection.
callbackfn.index - The index of the current element being processed in the collection.
callbackfn.array - The collection map
was called upon.
thisArg - An object to which the this
keyword can refer in the callbackfn
function. If thisArg
is omitted, undefined
is used as the this
value.
Returns the maximum value of the values in the collection or of the
given property among all the objects in the collection, or undefined
if the collection is empty.
Only supported for int, float, double and date properties. null
values
are ignored entirely by this method and will not be returned.
Optional
property: stringFor a collection of objects, the property to take the maximum of.
The maximum value.
An Error if no property with the name exists or if property is not numeric/date.
Returns the minimum value of the values in the collection or of the
given property among all the objects in the collection, or undefined
if the collection is empty.
Only supported for int, float, double and date properties. null
values
are ignored entirely by this method and will not be returned.
Optional
property: stringFor a collection of objects, the property to take the minimum of.
The minimum value.
A TypeAssertionError if no property with the name exists or if property is not numeric/date.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduce
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduce
was called upon.
initialValue - If initialValue
is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn
function provides this value as an argument instead of an element value.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduce
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduce
was called upon.
initialValue - If initialValue
is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn
function provides this value as an argument instead of an element value.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduce
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduce
was called upon.
initialValue - If initialValue
is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn
function provides this value as an argument instead of an element value.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduceRight
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduceRight
was called upon.
initialValue - If initialValue
is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn
function provides this value as an argument instead of an element value.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduceRight
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduceRight
was called upon.
initialValue - If initialValue
is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn
function provides this value as an argument instead of an element value.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduceRight
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduceRight
was called upon.
initialValue - If initialValue
is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn
function provides this value as an argument instead of an element value.
Remove the listener callback
from the collection instance.
Callback function that was previously added as a listener through the Collection.addListener method.
a TypeAssertionError If callback
is not a function.
Optional
start: numberOptional
end: numberA new array containing the elements between the start and end indices.
start - Zero-based index at which to begin extraction.
end - Zero-based index at which to end extraction. It extracts up to but not including end
.
Create a frozen snapshot of the collection.
Values added to and removed from the original collection will not be reflected in the Results returned by this method, including if the values of properties are changed to make them match or not match any filters applied.
This is not a deep snapshot. Realm objects contained in this
snapshot will continue to update as changes are made to them, and if
they are deleted from the Realm they will be replaced by null
at the
respective indices.
Results which will not live update.
Optional
thisArg: anytrue
if the callback function returns a truthy value for any collection element; otherwise, false
.
predicate - A function to test for each element.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection every
was called upon.
thisArg - An object to which the this
keyword can refer in the predicate function. If thisArg
is omitted, undefined
is used as the this
value.
Returns new Results that represent a sorted view of this collection.
A collection of Realm Objects can be sorted on one or more properties of
those objects, or of properties of objects linked to by those objects.
To sort by a single property, simply pass the name of that property to
sorted()
, optionally followed by a boolean indicating if the sort should be reversed.
For more than one property, you must pass an array of
sort descriptors which list
which properties to sort on.
Collections of other types sort on the values themselves rather than properties of the values, and so no property name or sort descriptors should be supplied.
Optional
reverse: booleanSort in descending order rather than ascended.
It may not be applied if descriptor
is an array of sort descriptors.
Results sorted according to the arguments passed in.
An Error if a specified property does not exist.
Returns new Results that represent a sorted view of this collection.
A collection of Realm Objects can be sorted on one or more properties of
those objects, or of properties of objects linked to by those objects.
To sort by a single property, simply pass the name of that property to
sorted()
, optionally followed by a boolean indicating if the sort should be reversed.
For more than one property, you must pass an array of
sort descriptors which list
which properties to sort on.
Collections of other types sort on the values themselves rather than properties of the values, and so no property name or sort descriptors should be supplied.
The property name(s) to sort the collection on.
Results sorted according to the arguments passed in.
An Error if a specified property does not exist.
Returns new Results that represent a sorted view of this collection.
A collection of Realm Objects can be sorted on one or more properties of
those objects, or of properties of objects linked to by those objects.
To sort by a single property, simply pass the name of that property to
sorted()
, optionally followed by a boolean indicating if the sort should be reversed.
For more than one property, you must pass an array of
sort descriptors which list
which properties to sort on.
Collections of other types sort on the values themselves rather than properties of the values, and so no property name or sort descriptors should be supplied.
The property name(s) to sort the collection on.
Optional
reverse: booleanResults sorted according to the arguments passed in.
An Error if a specified property does not exist.
Experimental
Add this query result to the set of active subscriptions. The query will be joined
via an OR
operator with any existing queries for the same type.
Options to use when adding this subscription (e.g. a name or wait behavior).
A promise that resolves to this Results instance. This API is experimental and may change or be removed.
Computes the sum of the values in the collection or of the given property among all the objects in the collection, or 0 if the collection is empty.
Only supported for int, float and double properties. null
values are
ignored entirely by this method.
Optional
property: stringFor a collection of objects, the property to take the sum of.
The sum.
An Error if no property with the name exists or if property is not numeric.
The plain object representation for JSON serialization. Use circular JSON serialization libraries such as @ungap/structured-clone and flatted to stringify Realm entities that have circular structures.
An array of plain objects.
Bulk update objects in the collection.
The name of the property.
The updated property value.
An Error if no property with the name exists.
2.0.0
An iterator with all values in the collection.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values | Array.prototype.values()}
Generated using TypeDoc
Instances of this class are typically live collections returned by objects() that will update as new objects are either added to or deleted from the Realm that match the underlying query. Results returned by snapshot()}, however, will not live update (and listener callbacks added through addListener() will thus never be called).
See
https://www.mongodb.com/docs/realm/sdk/react-native/model-data/data-types/collections/