Docs Menu

Docs HomeRealm

Live Queries - Node.js SDK

On this page

  • Live Objects
  • Collections
  • Change Notifications

You can query a realm to find objects based on their type and the values of their properties. Objects and queries always reflect the latest state of an object and emit notifications that can update your app whenever data changes.


Learn How to Define and Run Queries

For code examples that show how to read and filter Realm objects with the Node.js SDK, see Read Operations.

Data in Realm is live, which means that an object always reflects its most recent saved state and read operations never block. Objects automatically update in response to changes, so you can see up-to-date data in your application without running a new query.


Memory-mapped Realm Objects

Realm can support live objects because it memory-maps objects in your application directly to data stored in the realm file instead of a copy of the data stored in memory.

A results collection represents all objects in a realm that match a query operation. In general you can work with a collection like a regular JavaScript array but collections don't actually hold matching Realm objects in memory. Instead they reference the matched objects, which themselves map directly to data in the realm file.


Pagination & Limits

Some queries only need to access a subset of all objects that match the query. Realm's lazy-loaded collections only fetch objects when you actually access them, so you do not need any special mechanism to limit query results.

For example, if you only want to find 10 matching objects at a time (such as in a paged product catalog) you can just access ten elements of the results collection. To advance to the next page, access the next ten elements of the results collection starting at the index immediately following the last element of the previous page.

Realm objects and collections always reflect the latest state of your data when you read them. Realm emits a change notification whenever the state of your data changes, which lets you reactively update your app in response to committed write transaction.

You can register three types of notification listeners:

  • A realm listener fires whenever any object in a realm changes.

  • A collection listener fires whenever a specific query matches a new set of objects or when any matched object changes.

  • An object listener fires whenever a specific object is deleted or has one or more properties modified.


Learn How to React to Changes

For code examples that show how to define, register, and clean up change notification listeners with the Node.js SDK, see React to Changes.

←  Realms - Node.js SDKWrite Transactions - Node.js SDK →
Share Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.