Home > OS >  Should I store boolean fields in arrays or in an object?
Should I store boolean fields in arrays or in an object?

Time:10-04

In my app, I have a form in which users choose a set of features they like. Suppose the features are:

["wifi", "tv", "radio", "pool", "kitchen", "balcony"]

But there are about 30 of those features.

However, in the database, is it more efficient to store it as an array of only the selected ones:

["wifi", "tv", "balcony"]

or to store it as the following:

{
   wifi: true,
   tv: true,
   radio: false,
   pool: false,
   kitchen: false,
   balcony: true,
}

Note that the operations on those data include getting them from the database and displaying what the user likes and doesn't like.

CodePudding user response:

Since in the case of both Cloud Firestore and the Realtime Database, we are charged by the amount of data we download, then it's always recommended to only store data that we need, and nothing more. So in your case, only the one that have the values of true.

  • Related