Nested documents are displayed as "[Object object]" in Document Details on admin panel

Expected behavior

https://docs.forestadmin.com/documentation/reference-guide/models/enrich-your-models#managing-nested-documents-in-mongoose

Actual Behavior

I have a field described in Mongoose schema as:

  'gallery': {
    'thumbnail': {
        'url': String,
        'cloudId': String,
        'type': String,
        'duration': Number,
        'size': Number,
    },
  },

For some reason I see this field in .forestadmin-schema.json as:

{
      "field": "gallery",
      "type": {
        "fields": [{
          "field": "thumbnail",
          "type": "String"
        }]
},

And it looks like this in admin panel:

image

So I can’t view or edit this nested document. But the most annoying thing that I can’t edit my document at all, because every time I save it I lose gallery.thumbnail field as it’s rewritten with “[object Object]” in my database.

Context

Please provide any relevant information about your setup.

  • Express Version: ~4.16.3
  • Database Dialect: Mongodb
    MongoDB server version: 3.6.12

Hi @Artem_Nazarenko,

I think you issue comes from the fact that type is a “reserved” keyword in Mongoose:
https://mongoosejs.com/docs/schematypes.html#type-key

Can you try to edit you schema this way:

  'gallery': {
    'thumbnail': {
        'url': String,
        'cloudId': String,
        'type': { type: String },
        'duration': Number,
        'size': Number,
    },
  },

and let us know if it fixes your issue :pray:

3 Likes

Hi @arnaud,

It worked! Thank you for the help!