'Modifying Schema only for one document

I'm creating an application in the MERN stack and I stumbled upon a problem. I will start by explaining how that app is going to work.

So, in that application users can create their Collections. It can be anything - a collection of books, a collection of a favorite food - anything. Now in these Collections, they can create Items - for example, specific books.

We can navigate through the application to the different Collection Pages or the specific Item Pages in those Collections. You get the idea. There is a list of all the Collections on the main page and we can click e.g. Books Collection, then click on the Harry Potter item, and we will visit the Page for that specific book.

When a user creates an Item, he has to add a name and tag to it. But the user can set his own fields, like for example Author field for that Books Collection. Then every Item (book) will gain that Author field. It's obvious, that the main Item Schema is not affected by that additional field. Because we don't wanna the Author field in the Favourite Food Collection.

Anyway, I know how to modify data of already existing Items, but how to change that Schema for an Items that user gonna create in the future? Because if the user added Author field, we obviously want that field to show every time that user creates a new Item (book) in that certain Collection. Should I create a whole new Schema, only for the modified document? Or is there a different, more approachable way of achieving what I want right here?



Solution 1:[1]

As far as saving dynamic data in the collection, you could use Mixed Type or Object Type, see more info here

For keeping track of the fields the user has used previously, we could maintain a array within, having all the fields

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Usama Masood