Hello my data id is displayed in this format [object Object]
“express”: “^4.18.2”,
“mongoose”: “^7.1.1”,
“@forestadmin/agent”: “^1.8.13”,
“@forestadmin/datasource-mongoose”: “^1.4.0”,
code :
const logger = require('winston');
const { createAgent } = require('@forestadmin/agent');
const { createMongooseDataSource } = require('@forestadmin/datasource-mongoose');
const express = require('express');
const connection = require('./mongoose-models');
module.exports = async () => {
try {
logger.info('[EXPRESS FOREST] Initializing forest');
process.env.FOREST_ENV_SECRET = CONFIG.credentials.forest.env_secret;
process.env.FOREST_AUTH_SECRET = CONFIG.credentials.forest.auth_secret;
// process.env.NODE_ENV = CONFIG.env_type;
const datasource = createMongooseDataSource(connection, { flattenMode: 'none' });
const agent = createAgent({
authSecret: process.env.FOREST_AUTH_SECRET,
envSecret: process.env.FOREST_ENV_SECRET,
isProduction: false,
loggerLevel: 'Error', // Valid values are 'Debug', 'Info', 'Warn' and 'Error'
logger: (logLevel, message) => {
logger.error(logLevel, message);
},
}).addDataSource(datasource);
const app = express();
agent.mountOnExpress(app).start();
app.listen(3000);
} catch (err) {
logger.error(err);
}
};
mongoose model:
const mongoose = require('mongoose');
const connectionString = 'mongodb://localhost:27017/freetest';
const connection = mongoose.createConnection(connectionString);
connection.model(
'persons',
new mongoose.Schema({
name: String,
age: Number,
// Nested object
address: { streetName: String, city: String, country: String },
// List of nested objects
bills: [{ title: String, amount: Number, issueDate: Date, payedBy: [String] }],
}),
);
module.exports = connection;
Failure Logs
GET /persons/%5Bobject%20Object%5D?{
timezone: ****
}
Record does not exists
- Environment name: local
- Agent (forest package) name & version: lasted
- Database type: mongo db