Uh oh, no collections found. (creating a fresh project, then turning into typescript = not fetching anything)

Hello! :slight_smile:

I thought it was the good time to close my previous issue as I think that now, I have a reproducible bug :slight_smile:

As I was trying to update my project from version 5.xxx to 7/8, I was like (at the end), let’s create a fresh new project.

I so created a new project (mostly to test the upgrade/translate) with the latest version of forest-cli. Well, if you create a project, then following (in the right order, from top to bottom) the following doc:

You will see that you get this amazing… empty… screen Uh oh, no collections found.

Note: It might have some breaking changes between the version 8 and your doc, I am aware of it. I just want to get to the latest version so I don’t have to struggle for a while…

Expected behavior

When I follow the two following documentation, I should be able to access my database. When I create the project, I have access to it.

Actual behavior

Once I translate config/databases.ts, middlewares/forestadmin.ts, models/index.ts and the models under models/, I have this screen…

I tried for a while to see if there is any “hidden logs” or “silent errors” but nothing…

Failure Logs

I have no logs :confused:

Context

Let me share you my files :slight_smile:

config/database.ts

import { ConnectionOptions } from "mongoose";
import { DatabaseConfiguration } from "forest-express-mongoose";
import { resolve } from 'path';

const databaseOptions: ConnectionOptions = {
  useNewUrlParser: true,
  useUnifiedTopology: true,
};

const databasesConfiguration: DatabaseConfiguration[] = [{
  name: 'default',
  modelsDir: resolve(__dirname, '../models'),
  connection: {
    url: process.env.DATABASE_URL,
    options: { ...databaseOptions },
  },
}];

export default databasesConfiguration;

middlewares/forestadmin.ts

import * as chalk from 'chalk';
import { join } from 'path';
import { init, LianaOptions } from "forest-express-mongoose";
import { objectMapping, connections } from '../models';
import { Application } from "express";

export = async function forestadmin(app: Application): Promise<void> {
  const lianaOptions: LianaOptions = {
    configDir: join(__dirname, '../forest'),
    envSecret: process.env.FOREST_ENV_SECRET,
    authSecret: process.env.FOREST_AUTH_SECRET,
    objectMapping,
    connections,
  }

  app.use(await init(lianaOptions));

  console.log(chalk.cyan('Your admin panel is available here: https://app.forestadmin.com/projects'));

  return;
};

models/notes.ts

// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
import {Schema} from 'mongoose';

export interface INote {
    created_at: number,
    name: string,
    content: string,
}

// This section contains the properties of your model, mapped to your collection's properties.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const schema = new Schema<INote>({
    'created_at': {type: Number, required: true},
    'name': {type: String, required: true},
    'content': {type: String, required: true},
}, {
    timestamps: false,
});

export default schema;

models/index.ts

import * as Mongoose from 'mongoose';
import {model} from 'mongoose';
import databasesConfiguration from '../config/databases';
import noteSchema, {INote} from './note';

const connections: Record<string, Mongoose.Connection> = {};
const objectMapping = Mongoose;

const connection = Mongoose.createConnection(databasesConfiguration[0].connection.url, databasesConfiguration[0].connection.options);
connections[connection.name] = connection;

let Notes = model<INote>('Notes', noteSchema, 'Notes');

export {
    objectMapping,
    connections,
    Notes,
};

package.json

{
  "name": "emixam23-update1",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node ./dist/server.js",
    "build": "rm -rf ./dist && npm run compile && npm run cp-config",
    "dev": "tsc-watch --onSuccess \"node ./dist/server.js\"",
    "compile": "tsc",
    "lint": "eslint . -c .eslintrc.json --ext .ts",
    "cp-config": "cp .env ./dist/"
  },
  "dependencies": {
    "body-parser": "1.19.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "~4.17.1",
    "express-jwt": "6.0.0",
    "forest-express-mongoose": "^8.0.0",
    "mongoose": "~5.8.2",
    "morgan": "1.9.1",
    "require-all": "^3.0.0"
  },
  "devDependencies": {
    "@types/express": "^4.17.13",
    "@types/mongoose": "^5.11.97",
    "@types/node": "^16.4.3",
    "tsc-watch": "^4.4.0",
    "typescript": "^4.3.5"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "pretty": true,
    "sourceMap": false,
    "target": "es2017",
    "outDir": "./dist",
    "baseUrl": "./",
    "types" : ["node", "express", "forest-express-mongoose"],
    "allowJs": true
  },
  "include": ["./**/*", ".env"],
  "exclude": ["node_modules", "dist"]
}

I hope I will be able to make it work soon, really need it to move forward in our project :slight_smile:

Thanks again for your work

Max

Hello @Emixam23 :wave:

I’m glad to see that you re-created a project from scratch to use TypeScript :raised_hands:

I’m also sorry that you are encountering issues.

By looking at your file, I’ve seen that you are creating a connection with createConnection, but you don’t use it to instantiate you models. You are using model directly from the mongoose package, and if I’m not mistaken this adds models in the default mongoose connection. By using the createConnection function, you are not setting any default connection.

Can you try to instantiate your models using the following please ?

connection.model<INote>('Notes', noteSchema, 'Notes')

Thanks for the files you shared, this really helps to investigate.

Keep me in touch :raised_hands:

2 Likes

Hey @Steve_Bunlon

What a mistake on my end… Thanks xD

Yes because I created my project with an old version of forest admin (v5 i guess) and so it’s too hard to update everything manually, so I recreated from scratch and now translating into typescript :slight_smile:

Best,

Hello @Emixam23 :wave:

Glad we figured the issue out!

Speaking about TypeScript, you generated a fresh project, and we have recently released version 8 of our lumber project. That being said, please keep in mind that the woodshop you used is intended to be used for projects version 7.

If you encounter any issue regarding types, architecture gap between version 7 and 8, or if you need any help to get your version 8 typescript project running, please don’t hesitate to create ticket and to ping me in. I will be glad to help you out :slight_smile:

Best,

Steve.

1 Like

Hey @Steve_Bunlon

Yeah, you right, as I said, I wanted to start fresh with your latest version, so I will be away from these upgrading challenges for a while :slight_smile:

Alright, I’ve created another issue, I just got a reply but I can ping you for sure :slight_smile:

I am also glad to find out those kind of issue (documentation, foresdtadmin itself, etc) because I know for sure it’ll help future customers of yours, even current ones :slight_smile:

Thanks again for your help :slight_smile:

Max