Ad

Is There A Maximum Number Of Attributes For Documents In Firebase?

I'm developing a game saver app using flutter and Firebase to store the data.

Actually my Firebase database looks like this:

games:{<br>
   // Team 1<br>
   player1: (reference to a player),<br>
   player2: (reference to a player)',<br>
   // Team 2<br>
   player3: (reference to a player),<br>
   player4: (reference to a player),<br>
   scoreTeam1: 2,<br>
   scoreTeam2: 1<br>
}<br>

// Usergames documents are indexed by the player unique ID as a key<br>
userGames: {<br>
   count: 2,  //this variable is increased every time i add a new game<br>
   game1: (reference to a game),<br>
   game2: (reference to another game),<br>
   ...<br>
   gameN: (another reference)<br>
}<br>

Player:{<br>
   name: 'player name'<br>
   ...(another player data)<br>
}<br>

With this implementation, the userGame documents will have every time more fields. My question is if there is a limit in the amount of fields that a document can contain. Also I would like to save lots of games, is this a proper way to implement the database?

Ad

Answer

Firebase usage limits can be found here:

https://cloud.google.com/firestore/quotas#collections_documents_and_fields

From that page, there is not a limit on the number of fields. However, the maximum size of a single document is 1MiB.

I would consider using a subcollection to store the game results, rather than adding more and more fields to the document.

Ad
source: stackoverflow.com
Ad