Feature(s) impacted
Collections creation.
Observed behavior
Collections created on the left, shouldn’t exist… because they are not collections, but references ! It seems it creates a collection for each reference.
Expected behavior
Only collections should appear on the left panel.
Failure Logs
No logs.
Context
- Project name: lereacteur-cfa
- Database type: mongoose
Packages :
"dependencies": {
"@forestadmin/agent": "^1.9.0",
"@forestadmin/datasource-mongoose": "^1.4.0",
"axios": "^1.4.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"module-alias": "^2.2.2",
"mongoose": "^7.2.0"
}
Models :
Model Enterprise
:
const mongoose = require("mongoose");
const schema = new mongoose.Schema(
{
name: String,
description: String,
logo: String,
wttj: String,
website: String,
city: String,
status: String,
employees: [{ type: mongoose.Schema.Types.ObjectId, ref: "Employee" }],
comments: [
{ type: mongoose.Schema.Types.ObjectId, ref: "CommentEnterprise" },
],
networks: [{ name: String, url: String }],
},
{
timestamps: true,
}
);
module.exports = function (connection) {
return connection.model("Enterprise", schema);
};
/models/index.js
contains :
const fs = require("fs");
const path = require("path");
module.exports = function (connection) {
const models = {};
const array = fs
.readdirSync(__dirname)
.filter((file) => file !== "index.js" && file.endsWith(".js"));
for (let index = 0; index < array.length; index++) {
const file = array[index];
const model = require(path.join(__dirname, file))(connection);
const modelName = path.basename(file, ".js");
models[modelName] = model;
}
return models;
};