Ask Your Question

Revision history [back]

There are a few ways to efficiently store and retrieve likes in Firestore/Document DB:

  1. Create a separate collection for Likes: Store the likes in a separate collection and use the document ID to link it to the main document. This allows for efficient queries and updates of like data, without affecting the main document.

  2. Use an Array in the Main Document: Store the likes as an array inside the main document. This allows for quick access and updates to the likes, but can become inefficient when the array gets too large.

  3. Use a Subcollection for the Likes: Similar to option 1, create a subcollection for likes under each main document. This allows for efficient queries and updates of like data, without affecting the main document.

  4. Use a Map in the Main Document: Store the likes as a map inside the main document. This allows for quick access and updates to the likes, but like an array, it can become inefficient when the map gets too large.

When retrieving likes from Firestore/Document DB, it is important to consider pagination, so that large amounts of data can be retrieved in chunks. Additionally, queries should be optimized to minimize the amount of data being sent back from the server.