Data management when modifying existing schemas
If you have taken all of the changes outlined in this chapter and added them to your application, you'll probably notice quite early that the list of projects on the user page doesn't display. This is because we have changed the schemaType
of createdBy
in projectSchema
from String
to ObjectId
. If you create new projects now, they will show up in the list.
In a development environment and a prototyping scenario, like we have here, this isn't a major issue as we can just add in some more temporary test data. If you're dealing with a live environment or pre-existing data that you want to use then you have to be a bit more careful when changing a schema in this way.
There are various ways you can handle this, both on the schema side and the data management side. A possible approach is to duplicate the existing schema in its entirety and changing the SchemaTypes that you need to.
To manage the data migration you could then either create a script to...