Help needed to install on Serverless/Express/Mongoose/Typescript

Hi there, I’m trying to setup Forest in my existing project with ‘forest-express-mongoose’ but I cannot find the detailed documentation or any example with forest.init method…

Here’s my code:

import serverless from 'serverless-http';
import express from 'express';
import cors from 'cors';
import mongoose from 'mongoose';
import forest from 'forest-express-mongoose';

import { userSchema } from '../database/models/User';
import { getConnection } from '../database/connection';

const app = express();
app.use(cors());

const User = mongoose.model('User', userSchema);

const sls = serverless(app);

export const handler = async (event, context) => {
    const connection = await getConnection();
    app.use(await forest.init({
        envSecret: process.env.FOREST_ENV_SECRET,
        authSecret: process.env.FOREST_AUTH_SECRET,
        objectMapping: [User],
        connections: { default: connection },
    }));
    
    return await sls(event, context);
};

And here’s the error I get from my app when Forest tries to connect to my localhost endpoint:

[forest] 🌳🌳🌳  An error occured while computing the Forest schema. Your application schema cannot be synchronized with Forest. Your admin panel might not reflect your application models definition. Right-hand side of 'instanceof' is not an object
{
  "stack": "TypeError: Right-hand side of 'instanceof' is not an object\n    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:175:37)\n    at getFieldSchema (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:301:13)\n    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:346:17\n    at tryCatcher (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/util.js:24:31)\n    at ReductionPromiseArray._promiseFulfilled (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/reduce.js:103:38)\n    at ReductionPromiseArray.init (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/promise_array.js:92:18)\n    at ReductionPromiseArray.init (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/reduce.js:40:10)\n    at Async._drainQueue (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/async.js:182:12)\n    at Async._drainQueues (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/async.js:187:10)\n    at Immediate.Async.drainQueues [as _onImmediate] (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/async.js:15:14)\n    at processImmediate (internal/timers.js:456:21)\n    at process.topLevelDomainCallback (domain.js:137:15)"
}

My guess is that the objectMapping property is wrong, but what am I supposed to provide here ?
By the way, all the models are already presents in the “connection” object, so is it really necessary to call the mongoose.model function again here ?

Hey @benjaming, and welcome to our community

Could you try using objectMapping: mongoose instead of an array of models?
Also, no mongoose model re-import is required here normally.

Our in-app integration (For both mongoose & sequelize) is pretty recent and we currently don’t have any documentation attached to it. Also, it seems like the onboarding for in-app mongoose is not crystal clear for the objectMapping value, so i’ll do a quick feedback to the team for all these points :raised_hands:

Let me know if that helps

1 Like

Hi @jeffladiray, thanks for your reply.

Indeed the provided example is a bit fuzzy…

About your suggestion to pass directly the objectMapping: mongoose that’s something I already tried earlier and it looks… worse:

RangeError: Maximum call stack size exceeded
    at isArrayLike (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:11400:25)
    at Function.isEmpty (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:11551:11)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:166:13)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4936:18
    at baseMap (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3584:7)
    at Function.map (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:9622:14)
    at schemaType (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:230:17)
    at getTypeFromMongoose (/Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:177:17)
    at /Users/benjamin/Dev/fmg-app/api/node_modules/forest-express-mongoose/dist/adapters/mongoose.js:233:17
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3585:27
    at /Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/benjamin/Dev/fmg-app/api/node_modules/lodash/lodash.js:3032:24)

Nevermind: I managed to validate this step by commenting out all the models except the User one in my connection object…
One of the other models is probably causing an infinite loop (nested documents maybe ?), anyway I’ll investigate this later.
Thanks for your support.

1 Like

Hey @benjaming,

Nice to know you fixed your issue.

Just in case others have a similar issue, here’s the generated file after a lumber generate, showing the parameters given to the middlewares/forestadmin.js

// models/index.js
const fs = require('fs');
const path = require('path');
const Mongoose = require('mongoose');
​
const databasesConfiguration = require('../config/databases');
​
const connections = {};
const db = {};
​
databasesConfiguration.forEach((databaseInfo) => {
  const connection = Mongoose.createConnection(databaseInfo.connection.url, databaseInfo.connection.options);
  connections[databaseInfo.name] = connection;
​
  const modelsDir = databaseInfo.modelsDir || path.join(__dirname, databaseInfo.name);
  fs
    .readdirSync(modelsDir)
    .filter((file) => file.indexOf('.') !== 0 && file !== 'index.js')
    .forEach((file) => {
      try {
        const model = require(path.join(modelsDir, file))(connection, Mongoose);
        db[model.modelName] = model;
      } catch (error) {
        console.error(`Model creation error: ${error}`);
      }
    });
});
​
db.objectMapping = Mongoose;
db.connections = connections;
​
module.exports = db;

With this file, you should be able to see the expected values.
Still, I’ll do a quick feedback to the team since objectMapping: models in the onboarding seems misleading. Thanks for your feedback :pray: