Archiving documents - Boolean field vs separate collection


#1

I have a collection of Posts which to users will be displayed in a feed.

The user can mark a post as archived in order to remove them from the main feed, and instead show them in another archived posts feed.

Furthermore, a post can have multiple comments. If an archived post receives a new comment, it should no longer be archived, and automatically be moved back into the main feed.

I have figured that I can take two approaches:

Either store a boolean archived flag on each Post, and then filter based on this value.

Or I can have a separate ArchivedPosts collection where I transfer the document to once it has been marked as archived.

The problem with 2 is that I will have to perform extra database operations to copy over the document, and remove it from the main Posts collection.

However, this way I have to filter through less documents when I want to display the main feed, because most of the archived documents no longer are interesting for the user.

Which approach seems the most optimal in my situation?


#2

It depends on how big your post collection can be and what percentage of archived posts you have per user.
Without these data I would use approach #1, filtering posts subscribed by the client to the ones not achieved. I would then create a second publication to retrieve only archived posts – if you need them.


#3

Initially I imagine each user to have between 100-1000 posts of which 30 aren’t archived, but I maybe over time that number would grow to 10000ish


#4

The main problem with putting it in a new collection is that you will have to then query the new collection for archived results. If you’re okay with that, it seems like a fine way to do it imo. Better to normalize on writes than on reads with mongodb.