Migrating fields

Sometimes as your content evolves, it's necessary to change some properties that can cause data loss if not migrated properly.

You can migrate your data on Canonic from one field to another by writing a simple script.

Let's say you have a list of entries in a table called movies. You want to migrate the actorName field which currently has only the actor's name. You want to link it to the Actor table instead.

  1. Create a new resource field in the graph called actor and link it to the Actor table.
  2. Run the following script

    import Canonic from '@canonic/apis/netflix-api'
    
    Canonic.initialize('TOKEN');
    Canonic.movies.migrate('actorName', 'actor', async (actorName) => {
      const actor = await Canonic.actors.find({ title: actorName })
      if (actor) return actor._id;
      else return null;
    })
  3. The script tries to migrate the actorName field. It tries to find the actor and passes its id instead.
Did you find what you were looking for?
👍
👎
What went wrong?
Need more help?We have a thriving Discordcommunity that can help you with all things Canonic. →