I have an array of objects like below as an input to a list of checkboxes,
[
{id: 1, name: 'abc', icon: 'icon_1'},
{id: 2, name: 'def', icon: 'icon_2'},
{id: 3, name: 'ghi', icon: 'icon_3'},
...
{id: 126, name: 'xyz', icon: 'icon_364'},
]
Like this, I have a few more arrays too. For countries, cities, user types, … all these are going to be constant values.
When it comes to storing & reading these static arrays in MongoDB, which of the following is the correct way with better performance.
-
Create a collection for each array & insert each object in the array as a document. In this case, to get the list of options for checkboxes, I have to read all 126 documents.
-
Create a single collection named “Global” and insert each document for each static array.
{_id: ObjectId('12345'), key: 'checkboxes_list', values: [my_checkbox_options_list]}
{_id: ObjectId('6789'), key: 'countries', values: [my_countries_list]}
{_id: ObjectId('5985'), key: 'usertypes', values: [my_usertypes_list]}
In this case, to read the list of countries, I just need to read only one document using collection.find({key: 'countries'})
?
Which of the approach is correct? How you are handling these constant values lists with Mongodb? For the user types list, there is a maximum of 5 records. Do I really need to create a separate collection to store only 5 records/documents?
In SQL, yes we do create a separate table for User type. But is it really good for MongoDB/NoSQL?
Thanks.