⚠️ Deprecated — These docs are no longer updated.
Visit the new docs at derbyjs.github.io/derby/ instead!

ANCHORQueries

Racer can fetch or subscribe to queries based on a model value or a database-specific query. When fetching or subscribing to a query, all of the documents associated with that query are also fetched or subscribed.

query = model.query(collectionName, path)

  • collectionName The name of a collection from which to get documents
  • path A model path whose value contains a documentId or an array of documentIds

query = model.query(collectionName, databaseQuery)

  • collectionName The name of a collection from which to get documents
  • databaseQuery A query in the database native format, such as a MonogDB query

ANCHORMongoDB query format

The sharedb-mongo adapter supports most MongoDB queries that you could pass to the Mongo find() method. See the Mongo DB query documentation and the query selectors reference. Supported MongoDB cursor methods must be passed in as part of the query. $sort should be used for sorting, and skips and limits should be specified as $skip and $limit. There is no findOne() equivalent—use $limit: 1 instead.

Note that projections, which are used to limit the fields that a query returns, may not be defined in the query. Please refer to the guide on using projections, which you can follow if you only want specific fields of a document transferred to the browser.

ANCHORQuery results

After a query is subscribed or fetched, its results can be returned directly via query.get(). It is also possible to create a live-updating results set in the model via query.ref().

results = query.get()

  • results Creates and returns an array of each of the document objects matching the query

scoped = query.ref(path)

  • path Local path at which to create an updating refList of the queries results
  • scoped Returns a model scoped to the path at which results are output