Ask Your Question
4

How can likes be stored and retrieved efficiently in FireStore/Document DB?

asked 2023-06-30 01:44:31 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-30 01:57:02 +0000

huitzilopochtli gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-30 01:44:31 +0000

Seen: 9 times

Last updated: Jun 30 '23