Skip to content

Passing an optional parameter to startAt() when querying FirebaseListObservable #362

@lf-alves

Description

@lf-alves

Hey,

I'm using a FirebaseListObservable to retrieve some messages from firebase and I was wondering how to use the firebase query startAt() method inside the query object. It's not a simple startAt(value) call, since I need to pass in the optional "key" parameter. However, it seems that there's no easy or straightforward way to accomplish that within the query object.

I tried the following:

    this.af.database.list('/messages', { 
    query: { 
        orderByChild: 'date', 
        startAt: {value: 'Some date', key: 'some key'}, //key is the optional parameter 
        limitToFirst: 10
        }
        })

but the firebase library (not angularfire2) complains:

ORIGINAL EXCEPTION: Error: Query: First argument passed to startAt(), endAt(), or equalTo() cannot be an object.

The startAt method can receive an optional parameter "key", as described in the firebase docs:
https://firebase.google.com/docs/reference/js/firebase.database.Query#startAt

I even tried $value and $key as the object properties, but firebase threw another Error.

Is this impossible to do with angularfire or is there a different syntax to do it?

This is how the query looks like with vanilla firebase:
firebase.database().ref('/messages').orderByChild('date').startAt(startAtValue, someKey).limitToFirst(10);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions