A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mongodb.com/docs/atlas/device-sdks/sdk/node/model-data/data-types/collections/ below:

Collections - Node.js SDK - Atlas Device SDKs

Realm has several types to represent groups of objects, which we call collections. A collection is an object that contains zero or more instances of one Realm type.

You can filter and sort any collection using Realm's query engine. Collections are live, so they always reflect the current state of the realm instance on the current thread. You can also listen for changes in the collection by subscribing to collection notifications.

A Results collection represents the lazily-evaluated results of a query operation. Results are immutable: you cannot add or remove elements to or from the results collection. Results have an associated query that determines their contents.

A List represents a collection of values of a single type. Lists are declared as a property within an object model, and are not associated with a query.

Lists behave like normal JavaScript arrays, except that they can only store values of a single type, which you indicate by setting the type property to the name of a valid property type or to the name of another Realm object type.

const PetOwnerSchema = {  name: "PetOwner",  primaryKey: "_id",  properties: {    _id: "objectId",    person: "Person",    pets: {      type: "list",      objectType: "string",             optional: false,     },  },};

You can only modify a List within a write transaction, and Lists are mutable: within the write transaction, you can add and remove elements to and from the List.

Realm only runs a query when you request the results of that query. This lazy evaluation enables you to write elegant, highly-performant code for handling large data sets and complex queries.

Like live objects, Realm collections are usually live:

A collection is not live when:

Combined with collection notifications, live collections enable reactive code. For example, suppose your view displays the results of a query. You can keep a reference to the results collection in your view class, then read the results collection as needed without having to refresh it or validate that it is up-to-date.

Important Indexes may change

Since results update themselves automatically, do not store the positional index of an object in the collection or the count of objects in a collection. The stored index or count value could be outdated by the time you use it.

As a result of lazy evaluation, you do not need any special mechanism to limit query results with Realm. For example, if your query matches thousands of objects, but you only want to load the first ten, access only the first ten elements of the results collection.

Thanks to lazy evaluation, the common task of pagination becomes quite simple. For example, suppose you have a results collection associated with a query that matches thousands of objects in your realm. You display one hundred objects per page. To advance to any page, simply access the elements of the results collection starting at the index that corresponds to the target page.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4