Querying Data

In our posts template, let's say we want to display the ten most recent blog posts. We can do this with by adding the following parameter to our posts route:

export default Ember.Route.extend({
  model: function() {
    return this.store.query('post', { orderBy: { publishedAt: 'desc' }, limit: 10 });
  }
});

Alternatively we can directly modify the the assumed Firestore reference, learn more about what query options are available in the Firestore documentation:

export default Ember.Route.extend({
  model: function() {
    return this.store.query('post', { query: ref => ref.orderBy('publishedAt', 'desc').limit(10) });
  }
});

This is useful for more advanced use cases.

Getting realtime updates to our queries

Use the RealtimeRouteMixin to get updates to records in your query while your route is in view.

import RealtimeRouteMixin from 'emberfire/mixins/realtime-route';

export default Route.extend(RealtimeRouteMixin, {
  model: function() {
    return this.store.query('post', { orderBy: { publishedAt: 'desc' }, limit: 10 });
  }
});

Query Options

Firestore

TODO write about the options available

    filter?: {[key:string]:any},
    where?: WhereOp|WhereOp[],
    endAt?: BoundOp,
    endBefore?: BoundOp,
    startAt?: BoundOp,
    startAfter?: BoundOp,
    orderBy?: OrderOp,
    include?: string

Query

    query?: (CollectionReference) => (Query|CollectionReference), 
    limit?: number

QueryRecord

    doc?: (CollectionReference) => (Query|DocumentReference)

Realtime Database

    query?: (Reference) => Reference,
    filter?: {[key:string]:string|number|boolean|null},
    endAt?: BoundOp,
    equalTo?: BoundOp,
    limitToFirst?: number,
    limitToLast?: number,
    orderBy?: string|OrderBy,
    startAt?: BoundOp

Query

    limit?: number