Search code examples
contentfulcontentful-api

How to update Contentful reference efficiently


I have a Content Model X with 200+ entries. One of the fields inside my Content Model X is a reference field referencing the Content Model A.

However, I realized that this Content Model A is no longer suitable for my use case so I created another Content Model B.

I wonder if there is an efficient way to update all the reference field for each entry from Content Model A to Content Model B ?

Or do I have to update the reference field manually for 200+ times ?

Thank you!


Solution

  • Before actually modifying 200+ content objects, another important question to be answered is that at what stage you will change your model. For instance, you cannot change the model if you have any entry (you have 200+). Therefore, it is important to follow versioning of the Content Model, for instance, v1 with reference to Model-A and v2 with reference to Model-B. Once you have finalized the structure of v2, use Content Management API to switch entries, hence change from Model-A to Model-B (https://www.contentful.com/developers/docs/references/content-management-api/)

    Of course we should try freeze the model structure, but these changes still happen and is a very common scenario. Therefore, changing manually is definitely not an option.

    Also, these Content Management APIs are suggested solution from Contentful, therefore scalable solution.