0

What's the difference between Mongoose Subdocs and Population, and what's the best to use?

I wanna build admins system and I want to know what's the best to use before starting.

Want to build something like this.

roles table ('Admin', 'User', 'Guest')
resources table ('Users', 'Projects', 'Programs')
permissions table ('Create', 'Read','Write','Delete','Deny')

Should I use Subdocs for one table or using Population for different tables?!

1 Answers1

0

Subdocuments are embeddded documents.

You can also have documents that reference other documents in the same table or other tables and just store the id(s) in the parent document. Populate is used to go ahead and fetch that data by the IDs stored in the document.

Think about SQL where you may store a primary key and need to fetch the data based on that primary key.

If you use sub documents every thing is stored in a single record which can impact performance.

This post goes into more details about them

twcardenas
  • 115
  • 2
  • 10