How to store static dropdown options in MongoDB? Multiple documents or Single Document with embedded array

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.

  1. 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.

  2. 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?


I have attempted Option 2 & below is the feedback.

  • it was fine until my requirement extends to manage array items programmatically
  • to push or update items in existing embedded array of a document, I was supposed to maintain unique id for items in array
  • Upsert is not directly possible with nested arrays - so 2 different statements has to execute for insert new item to array & update value of existing item
  • another issue is while insert, C# driver converts the property name “Id” to “_id” before inserting. Adding attribute [BsonElement(“Id”)] towards the property also not working. So I was forced to use name “_id” instead of “Id”

To add new item to existing nested array in a document,

To update existing item in a nested array of document,

I just read this!

To fix the “Id” to “_id” serialization for embedded documents, I have created a new property & explicitly mapped the element name “Id” to it.