user8512285
user8512285

Reputation:

Angular and Firebase - query with orderByKey correctly

Here I have a query, that works well: url is a $key generated by Firebase when Article gets created.

   findArticlesByUrl(url:any) {
        return this.afDb.list('articles', {
          query: {
            orderByKey: url,
            equalTo: url
          }              
        }).do(console.log);

What I am curious about is that I need to tell it twice to query list by the url. So in a code above I am kind of telling - "order this list by their keys and use url as a param value. Url value should be as in url"... That makes no sense. Am I doing it right?

Upvotes: 0

Views: 309

Answers (1)

Markus Kollers
Markus Kollers

Reputation: 3728

If your database looks like this:

articles
  "-KsWM-xif_wPxIvsu5CZ"
     prop1: "..."
     prop2: "..."
  "-KsWNf4AOuuGGsBfeIlg"
     prop1: "..."
     prop2: "..."

this should work:

findArticlesByUrl(url: string) {
   return this.afDb.object('articles/' + url).do(console.log);
}

Upvotes: 1

Related Questions