My data _id show in format [object Object] mongoose

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

Hi @Amine_KHALIFA and welcome to our community !

What display are you looking for for your id ?
You can change the display settings of a field through Edit layout mode, going through the settings of the specific collection and clicking on the specific field on the Select display widget dropdown.

Best regards,

Shohan

Thank you for your response @shohanr .

I checked the field widget, and I founded correct is a text

And I switched to Json viewer, but it still doesn’t work.

Hi @Amine_KHALIFA ,

Can I have some more information about “it doesn’t work” ?
Does it still render [object Object] ?
Do you have any error in console ?
What is the data in your id please ?

Best regards,

Shohan

Hi @shohanr,

Does it still render [object Object] ? yes

Do you have any error in console ? no

What is the data in your id please ?
My date is a string generated automatically with Mongo dB win i creat a new user ( field ‘_id’)

Best regards,

Hi @Amine_KHALIFA ,

What is the name of your project please ?

Hello @shohanr
the name of the project is Mobion_freefloating

Thanks to @shohanr for your assistance.
I have removed my node_modules and cleaned the cache. its working :sweat_smile:

1 Like