Using “array-contains” Query for Cloud Firestore Social Media Structure

后端 未结 2 2040
梦如初夏
梦如初夏 2021-01-07 04:22

I have a data structure that consists of a collection, called \"Polls.\" \"Polls\" has several documents that have randomly generated ID\'s. Within those documents, there is

2条回答
  •  渐次进展
    2021-01-07 04:47

    Would the "array_contains" query be another practical option for social media structure scalability?

    Yes of course. This the reason why Firebase creators added this feature.

    Seeing your structure, I think you can give it a try, but to responde to your question.

    What are the limitations on the "array_contains" query?

    There is no limitations regarding what type of data do you store.

    Is it practical to have an array stored in Firebase that contains thousands of users / followers?

    Is not about practical or not, is about other type of limitations. The problem is that the documents have limits. So there are some limits when it comes to how much data you can put into a document. According to the official documentation regarding usage and limits:

    Maximum size for a document: 1 MiB (1,048,576 bytes)

    As you can see, you are limited to 1 MiB total of data in a single document. When we are talking about storing text, you can store pretty much. So in your case, if you would store only ids, I think that will be no problem. But IMHO, as your array getts bigger, be careful about this limitation.

    If you are storing large amount of data in arrays and those arrays should be updated by lots of users, there is another limitation that you need to take care of. So you are limited to 1 write per second on every document. So if you have a situation in which a lot of users al all trying to write/update data to the same documents all at once, you might start to see some of this writes to fail. So, be careful about this limitation too.

提交回复
热议问题