Define Base Structure Firebase

0

How to set the structure below the JSON tree?

In an Angular application, can I have multiple registered multi-patient users with multiple queries for each user and each patient in a single Firebase database?

The question arises because if I have 100 patients for user X and 100 patients for user Y, the time to make the query can be delayed, because in the JSON tree patients will have 200 records.

Imagine a system with 100 users where each user has 10 patients, in the JSON tree of patients would have 1,000 records, when it comes to finding patients it may be slow.

    
asked by anonymous 06.02.2018 / 18:50

1 answer

0
  

In an Angular application, can I have multiple registered multi-patient users with multiple queries for each user and each patient in a single Firebase database?

Yes

  

The question arises because if I have 100 patients for user X and 100 patients for user Y, the time to make the query can be delayed, because in the JSON tree patients will have 200 records.

This can occur in Realtime Database, depending on the structure of the database, but by the image I believe you want to use the Cloud Firestor, which in the documentation ...

"Save surface queries for subcollections: You can query subcollections within a document instead of an entire collection, or even an entire document."

In other words, you can fetch an object without necessarily bringing all objects related to it, so do not worry about it

How to structure the data, take a look at here >, the advantages and disadvantages of each way of structuring the data are explained and exemplified, there are three ways:

Nested data in documents

You can nest complex objects as arrays (maps) in documents.

Advantages: If you have simple, fixed data lists that you want to keep in your documents, it's easy to set up and simplify the data structure.

Limitations: You can not run queries in nested lists. In addition, this feature is not as scalable as the other options, especially if the data expands over time. With larger or constantly growing lists, the document also grows, which can result in slower document retrieval times.

What use case is possible? In a chat app, for example, you can store the three most recently visited chat rooms as a nested list in their profile.

Subcollections

You can create collections in documents when there is data that can expand over time.

Advantages: As the lists grow, the size of the parent document does not change. You also have access to all the query features in the subcollections.

Limitations: You can not easily exclude subcollections or execute composite queries on them.

What use case is possible? In the same chat app, for example, you can create collections of users or messages in chat room documents.

Collections at the root level

Create collections at the root level of the database to organize different data sets.

Advantages: collections at the root level offer more flexibility and scalability, as well as advanced query in each collection.

Limitations: Data access, which is naturally hierarchical, can become increasingly complex as the database grows.

What use case is possible? In the same chat app, for example, you can create a collection of users and a collection of rooms and messages.

Analyze your application and choose what you think is most advantageous

    
13.03.2018 / 17:38