Smart Collection is not working

Dear Forest Admin team,

I was trying to create a smart collection following your instruction in this URL:

https://docs.forestadmin.com/documentation/reference-guide/collections/create-a-smart-collection

Unfortunately, I was successful.

Here is my setting:

  1. Data source is PostgreSQL
  2. I have installed admin with docker and docker container is running.
  3. I have installed npm install --global forest-cli
  4. E.g. login with forest login is working properly.
  5. My project qms-forest displays all initial collections from the database.

Now I tried to create a customer stats exactly as it is described in your instruction:

  1. My Forest Backend Admin is called qms-forest and so I placed right in this root folder a file customer_stats.js
  • However, this module is not exported, how exactly should this code work please?
  • In the line 2, you are also importing models, but you don’t use that afterwards, what is it then for please?
  1. In the folder routes/customer_stats.js I placed the other customer_stats.js files according to your instructions.
    In this document, I see there the line 4 stating: const { connections } = require('../models');
    However, I do not have such file in my folder models. Don’t you have a link reference where it is explained how this is supposed to work please?

Thank you very much for your help,
Vaclav

Hey @Vaclav :wave:

  1. My Forest Backend Admin is called qms-forest and so I placed right in this root folder a file customer_stats.js
  • However, this module is not exported, how exactly should this code work please?

The files located in the forest folder are dynamically loaded by forest-express-sequelize, that’s why they are not exported.

  • In the line 2, you are also importing models , but you don’t use that afterwards, what is it then for please?

Often, when you have to edit these files, you’ll need to have access to your Sequelize model (Smart action, smart fields, …). It is not required by default and you can safely remove it if you don’t need it.

  1. In the folder routes/customer_stats.js I placed the other customer_stats.js files according to your instructions.
    In this document, I see there the line 4 stating: const { connections } = require('../models');
    However, I do not have such file in my folder models . Don’t you have a link reference where it is explained how this is supposed to work please?

I’m actually not sure of the version of forest-express-sequelize you are using, but I’m expecting at least v7 according to the code you provide.

In the models/index.js, you should have an exported connections property. connections.default should (By default) return your sequelize database connection, which can then be used to directly query your database (Via the sequelize .query)

Let me know if that helps or if you have any other questions :pray: