# Unable to update the layout for sub document definitions (mongodb)

**URL:** <https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869>\
**Category:** Help me!\
**Created:** [February 17, 2021, 10:40pm UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869 "2021-02-17T22:40:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emixam23](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/emixam23/32/1350_2.png) [@Emixam23](https://community.forestadmin.com/u/Emixam23)\
**Post date:** [February 17, 2021, 10:40pm UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/1 "2021-02-17T22:40:17Z")

</div>

Hey guys!

As posted in some other(s) topic(s), I have a couple of collection(s) (mongodb) but for some of them, I have documents like this:

> Note: I will only show an “interface” approche, but schema would result to be the same, don’t worry, we keep it simple.

**item.ts**

```javascript
import { Schema, Document, model} from 'mongoose';
import * as notes, {INotes} from './notes.ts';

interface IItem extends Document {
  notes: [INote],
  // ...
}

const schema = new Schema({
  'notes': [notes]
  // ...
}, {
  timestamps: false,
});

export default model<IItem>('items', schema, 'Items');

```

So, note is basically a simple model which isn’t a collection itself and used only as nested document schema.

**note.ts**

```javascript
import { Schema, Document, model, Types} from 'mongoose';

export interface INote extends Document {
  title: string,
  message: string,
  author_id: Types.ObjectId
}

const schema = new Schema({
  "title": String,
  "message": String,
  'author_id': { type: Types.ObjectId, ref: 'xxx' },
}, {
  timestamps: false,
});

export default model<INote>('notes', schema);

```

The thing is, I am able to edit the layout from Forest Admin UI of the items (the collection display, the single item fields, etc) but I am not able to edit the fields types.

By example, one of the field is an author ID and, instead of a “text input”, I would like to put a Dropdown because I am in the same situation as I was in this topic: [Dropdown(s) of constants/foreign keys on create/update from UI - #3 by Emixam23](https://community.forestadmin.com/t/dropdown-s-of-constants-foreign-keys-on-create-update-from-ui/1835/3) @Arnaud_Moncel @remi.

I searched but couldn’t find the way to edit the “widget” from “text input” to “dropdown” when it’s a nested document.

I am close to be done, it’s amazing how fast you can build a backoffice using forest admin when you don’t have much skills in web dev!

Thanks!

Max,

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [February 22, 2021, 3:25pm UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/2 "2021-02-22T15:25:30Z")

</div>

Hello @Emixam23 and sorry for the late response,

To change a _text input_ field into a _dropdown_ you can simply do it via the layout editor. This [little video](https://www.loom.com/share/134f3066ba3c45d0b0500639d9bb777b) illustrates how to do it.

Let me know if it helps! 🙂

---

<div class="post-metadata">

**Author:** ![Emixam23](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/emixam23/32/1350_2.png) [@Emixam23](https://community.forestadmin.com/u/Emixam23)\
**Post date:** [February 24, 2021, 2:24pm UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/3 "2021-02-24T14:24:03Z")

</div>

Hey 🙂

Thanks for your answer, sadly, it doesn’t help as my situation is different 😕

Try to have a collection with the configuration explained above, and try to edit the subdocument “Note”.  
In the “Related Data” section, your notes will appear once you are on an item.

Try to edit the layout, you won’t be able to change the “Edit Widget”. It does work for the document, but not for sub documents (e.i. : the layout edition works on Item, but not on Note)

exemple with a Item document containing an array of notes:

```javascript
{
  "_id": ObjectId("xxx"),
  "name": "My first note",
  "notes": [
    {
      "title": "My first note",
      "message": "We are currently trying to reproduce a situation",
      "author_id": ObjectId("yyy"),
      "priority": 2
    }, {
      "title": "My first note",
      "message": "We are currently trying to reproduce a situation",
      "author_id": ObjectId("yyy"),
      "priority": 3
    }
  ]
}

```

This note has a “priority” field as you can see. However, I want it to be a dropdown of “constants” which are staticly defined. I already have done it on Item, so I know how to do it and it works perfectly. But now, I want to do it on this nested document too, but as you can see (if you reproduce the issue, it’s not possible… If Note was a "foreign object) linked throught a foreing key, it wouldn’t be a nested document anymore “as it would have its own collection” so I would be able to create this dropdown using your technic on the video. But here, it’s a nested document, not a document from another collection.

Hope it helps you to better understand! 🙂

Thanks,

Max

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [March 5, 2021, 8:58am UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/4 "2021-03-05T08:58:13Z")

</div>

Hi @Emixam23 👋 unfortunately it is not possible yet. The actual behavior of nested document today is:

- the first level estimate sub field type and put default widget on it.
- the second level just set a json editor widget to edit it.

So I will push your request on our product board.

---

<div class="post-metadata">

**Author:** ![Shem](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/shem/32/3823_2.png) [@Shem](https://community.forestadmin.com/u/Shem)\
**Post date:** [January 11, 2022, 8:43am UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/5 "2022-01-11T08:43:37Z")

</div>

Hi, any updates on supporting nested documents?

---

<div class="post-metadata">

**Author:** ![morganperre](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/morganperre/32/1296_2.png) [@morganperre](https://community.forestadmin.com/u/morganperre)\
**Post date:** [January 11, 2022, 8:55am UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/6 "2022-01-11T08:55:04Z")

</div>

Hello @Shem ! Welcome to our community 🎉 🎊

We have a new feature called **flatten nested fields** available for **mongodb** but we don’t support edit of arrays of embedded fields. You can find more information here ⬇

> **[Flatten nested fields (MongoDB)](https://docs.forestadmin.com/documentation/reference-guide/fields/flatten-nested-fields-mongodb)**

Let me know if that was what you were looking for.

Best regards,  
Morgan

---

<div class="post-metadata">

**Author:** ![Shem](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/shem/32/3823_2.png) [@Shem](https://community.forestadmin.com/u/Shem)\
**Post date:** [January 11, 2022, 9:12am UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/7 "2022-01-11T09:12:04Z")

</div>

Yes, I know the **flatten nested fields** option, but it’s not helping me.  
I have a mongo object that looks something like that:

```javascript
doc: {
  _id: string,
  items: [
    name: string,
    subItems: [
      prop1: string,
      prop2: string,
    ]
  ]
}

```

So no way to have a decent view / edit capabilities for items or subItems

---

<div class="post-metadata">

**Author:** ![morganperre](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/morganperre/32/1296_2.png) [@morganperre](https://community.forestadmin.com/u/morganperre)\
**Post date:** [January 11, 2022, 10:09am UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/8 "2022-01-11T10:09:23Z")

</div>

Hey again,

Indeed as I mention we don’t support, in a clean way, the display/edit of subDocuments embedded fields.

We have some work ongoing on this subject. I’ll push again the request on our product board so we can tackle it in a near future.

Kind regards,  
Morgan

---

<div class="post-metadata">

**Author:** ![Thong\_Dang](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/thong_dang/32/6446_2.png) [@Thong\_Dang](https://community.forestadmin.com/u/Thong_Dang)\
**Post date:** [January 19, 2024, 2:47am UTC](https://community.forestadmin.com/t/unable-to-update-the-layout-for-sub-document-definitions-mongodb/1869/9 "2024-01-19T02:47:48Z")

</div>

It’ had been two years guys. Is that too hard to support this feature?
