0

I have 2 collections all_files and trashed_files. File item object in each of these collections is the same { name, type, metadata }. Is it a good idea to create only one collection with one boolean property isTrashed in the file item object like { name, type, metadata, isTrashed } and delete the trashed_files collection?

Currently to delete the file item, I have first delete item from all_files collection and add it to trashed_files collection. Although mongo operations are atomic, this requires two operations. With the new schema I will only have to update isTrashed property for the concerned file item. But my worry is that for a very large collection this will lead to slow performance when I want to find all trashed files from the all_files collection.

Which schema is better? I have read about single/multi table inheritance and denormalized nature of the mongodb.

  • You will benefit from removing the data duplication (saves disk space, memory and maintenance) - by having a single collection. What was the reason why there are two collections with same data - needs to be understood clearly. – prasad_ May 05 '22 at 04:54
  • @prasad_ Well idea behind for 2 separate models have to do with separation of concerns. If a single model is maintained then every time I make a request, I have to make sure to filter out trashed files. Example I am trying to find out liked files, and some of the liked files are trashed, if I don't filter out trashed files I may end up serving them instead. And later I might have other filters like synced, offline, etc – Andy Puneri May 10 '22 at 06:31
  • Then, you need to look at the CRUD queries you perform most often on the data - what queries are important, how much data you are handling are some of the main concerns. – prasad_ May 10 '22 at 11:42

0 Answers0