Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularfire2 - Query table with a param

I am trying to retrieve all the items that have a param with a certain key.

Here is the function that fills an array with the retrieved items:

    this.subscription = this.activatedRoute.params.subscribe(
     (param: any) => {
    let postId = param['id'];
    console.log(postId);
      this.postsService.subscribePostReplies(postId)
             .do(console.log)
            .subscribe(posts => { this.posts = posts; this.cdr.detectChanges(); });
     });

Here is the method within the service:

 subscribePostReplies(postKey: string) {
    return this.af.database.list('posts', {
        query: {
            orderByChild: 'repliedTo',
            equalTo: postKey
        }
    });
 }

Problem is the page refreshes when the query happens and I also get alerted with: FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "repliedTo" at /posts to your security rules for better performance

like image 808
Pete Avatar asked Jun 21 '26 15:06

Pete


1 Answers

Your warning pretty much spells it out.

WARNING: Using an unspecified index. Consider adding ".indexOn": "repliedTo" at /posts to your security rules for better performance

".indexOn": "repliedTo" @ /posts will looks something like this:

{
  "rules": {
    ".read": true,
    ".write": true,

    "posts": {
      ".indexOn": "repliedTo"
    }
  }
}

Remember, this is just a warning and indexOn is not required for development.

Indexes are not required for development unless you are using the REST API. The realtime client libraries can execute ad-hoc queries without specifying indexes. Performance will degrade as the data you query grows, so it is important to add indexes before you launch your app if you anticipate querying a large set of data.

like image 82
ksav Avatar answered Jun 24 '26 08:06

ksav