Choosing Data in Firebase

I shot the Firebase / Angular video you made and was immediately very worried about the project I just started. One thing I'm struggling to figure out with is how to select data at sub-levels. I mean: let's say I had something like this:

Firebase data screenshot

How can I select all records with agent_1 and / or records with box_id over 600 (plus other fields) without creating a large number of indexes for each search term? I really do not want to download all the data to the client, and then iterate over the records, as there will eventually be a lot of data.

In the end, the application should be able to filter data in different fields at the same time. For example, I will have a selection box for agents that can return all agent_1 entries. Then I would add the filter "all boxes with identifier> 600", and then, possibly, "box weight" 24 kg ", etc.

It seems like I read, this is only possible if there is an id field for each record, and then an index dataset for each field with which you would like to search. It is simple enough for one field. However, I think the only way to filter data with additional fields is to get identifiers in the next set of index data and filter on the client.

Am I right in this approach? It seems pretty drawn out.

What would be surprising is: https://xxxxx.firebaseio.com/boxes/?agent=agent_1/?box_id > 600

Just a thought !:-)

Thanks!

+4
source share
1 answer

import angular first as below

import { AngularFireDatabase } from "angularfire2/database"; 

also import into app.module.ts

secondly, enter the database in your constructor as

  constructor(private database:AngularFireDatabase ){ const rootRef = database.database.ref(); var data= rootRef.child("boxes").orderByChild("agent").equalTo("agent_3") } 
0
source

Source: https://habr.com/ru/post/1495630/


All Articles