Configure database connection
This is the official documentation of the @forestadmin/agent Node.js agent.
Migrating from forest-express-sequelize
forest-express-sequelizeWhen using the onboarding wizard, you connected to your database using the @forestadmin/datasource-sql connector. To ease the migration, we recommend switching to the @forestadmin/datasource-sequelize connector.
Start by changing the dependency in your agent
$ npm install @forestadmin/datasource-sequelize sequelizeThen you will need to copy your Sequelize models to the new project and change the index file.
const { createAgent } = require('@forestadmin/agent');
const { createSequelizeDataSource } = require('@forestadmin/datasource-sequelize');
const sequelizeInstance = require('./sequelize-instance');
// Create agent and import collections from sequelize
const agent = createAgent(options).addDataSource(
createSequelizeDataSource(sequelizeInstance),
);Migrating from forest-express-mongoose
forest-express-mongooseConnect to the database
Connecting to a MongoDB instance is very similar: using the mongoose ODM is required. We officially support mongoose >= 6.0, but customers have reported working installations with 5.x.
You will need to:
Install the
@forestadmin/datasource-mongoosepackage.Copy your
mongoosemodels to the new project.Create a new
mongooseconnection to the same database as the old one.
Replicate your legacy agent flattener configuration
If you are using the forest-express-mongoose agent, you probably are using the flattener ↗ feature.
In the new agent, the flattener is more capable, but the behavior of the new auto mode is different.
To replicate the behavior of the old agent, you will need to use the manual mode and configure the flattener manually.
If you were using fieldsToFlatten in your old agent.
Otherwise
Last updated
Was this helpful?