Mongoose to postgres Sequelize Mongoose to postgres Sequelize mongoose mongoose

Mongoose to postgres Sequelize


I did the first one without an association. That's because I did not want a resulting separate table, as the array would just be used on this specific relation/collection (Category). I also knew I was going to be using Sequelize with Postgres. If you have the luxury of doing Sequelize with Postgres, you can use Postgres composite types:

sequelize.query(        "CREATE TYPE category_tags_type AS (type varchar,ref varchar );"        );

Then when that has run, you can do

const Category = sequelize.define( "category",     { name: Sequelize.STRING, description: Sequelize.string,       default_tags: '_category_tags_type'     }

The beginning underscore before category_tags_type tells sequelize this is an array.