# Array of Object IDs when creating new array item

**URL:** <https://community.forestadmin.com/t/array-of-object-ids-when-creating-new-array-item/7022>\
**Category:** Help me!\
**Created:** [February 1, 2024, 7:10pm UTC](https://community.forestadmin.com/t/array-of-object-ids-when-creating-new-array-item/7022 "2024-02-01T19:10:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DannySaludSativa](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/dannysaludsativa/32/3154_2.png) [@DannySaludSativa](https://community.forestadmin.com/u/DannySaludSativa)\
**Post date:** [February 1, 2024, 7:10pm UTC](https://community.forestadmin.com/t/array-of-object-ids-when-creating-new-array-item/7022/1 "2024-02-01T19:10:11Z")

</div>

## Feature(s) impacted

OneToMany, Schemas

## Observed behavior

When trying to create a new object I am unable to link the item I am trying to add to my array, please see images attached as this is very vague, im not so sure how to describe the issue

## Expected behavior

When it’s not an array it allows me to type the item and a dropdown will show me the items linked

## Context

- Environment name: Most Recent MongoDB NodeJs
- Agent (forest package) name & version: 9
- Database type: MongoDB
- Recent changes made on your end if any: None

Dock.ts

```javascript
const dockQueueItem = new Mongoose.Schema({
  **pickables: [{ type: Mongoose.Schema.Types.ObjectId, ref: "pickable" }]**,
  loaded: { type: Boolean, default: false },
  track: [String],
});

const dockSchema = new Mongoose.Schema(
  {
    identifier: { type: String, unique: true },
    queue: [{ type: dockQueueItem }],
    createdAt: { type: Date, default: Date.now },
  },
  {
    timestamps: false,
  },
);

```

The bolded part is the one I am having an issue with when adding a new Purchase order to my purchase orders array, it won’t show any available purchase order items, where as if I don’t make it an array it will show the dropdown to select

 ![Screenshot 2024-02-01 at 1.08.53 PM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/15e8a7f2dd2f2a19084355eb79aeba162dbb5309.png)

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 2, 2024, 8:03am UTC](https://community.forestadmin.com/t/array-of-object-ids-when-creating-new-array-item/7022/2 "2024-02-02T08:03:35Z")

</div>

Hello @DannySaludSativa,

Thanks for your feedback.

Could you please also share the declaration of your models?

If I follow the [documentation for MongoDB and forest-express-mongoose](https://docs.forestadmin.com/documentation/reference-guide/models/relationships), it seems that this syntax is supported:

Here is an example from the docs:

```js
module.exports = (mongoose, Mongoose) => {
  const schema = Mongoose.Schema({
    ...
    'orders': [{ type: Mongoose.Schema.Types.ObjectId, ref: 'orders' }],
    ...
  }, {
    timestamps: true,
  });

  return mongoose.model('customers', schema, 'customers');
};

```

It’s important to note that the value inside the `ref` needs to match the name of the declared **mongoose model**.

---

<div class="post-metadata">

**Author:** ![DannySaludSativa](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/dannysaludsativa/32/3154_2.png) [@DannySaludSativa](https://community.forestadmin.com/u/DannySaludSativa)\
**Post date:** [February 5, 2024, 3:09pm UTC](https://community.forestadmin.com/t/array-of-object-ids-when-creating-new-array-item/7022/4 "2024-02-05T15:09:54Z")

</div>

```javascript
const dockQueueItem = new Mongoose.Schema({
  **pickables: [{ type: Mongoose.Schema.Types.ObjectId, ref: "pickable" }]**,
  loaded: { type: Boolean, default: false },
  track: [String],
});

const dockSchema = new Mongoose.Schema(
  {
    identifier: { type: String, unique: true },
    queue: [{ type: dockQueueItem }],
    createdAt: { type: Date, default: Date.now },
  },
  {
    timestamps: false,
  },
);

```

That is the declaration of my model ^^

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 5, 2024, 3:13pm UTC](https://community.forestadmin.com/t/array-of-object-ids-when-creating-new-array-item/7022/5 "2024-02-05T15:13:04Z")

</div>

Where are the lines with the call to `mongoose.model`?

In my example I first call `const schema = Mongoose.Schema` as you do with `dockQueueItem = new Mongoose.Schema` but at the end of the function, I return `return mongoose.model('customers', schema, 'customers');`.

The name of the collection in this call is important for references to be correctly interpreted by Forest Admin.

That’s why I’m asking for this declaration ; to check that everything is matching.
