# How to insert item with multi-reference field

**URL:** <https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 7, 2019, 6:07pm UTC](https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169 "2019-03-07T18:07:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![plomteuxquentin](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/plomteuxquentin/32/9345_2.png) [@plomteuxquentin](https://forum.wixstudio.com/u/plomteuxquentin)\
**Post date:** [March 7, 2019, 6:07pm UTC](https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169/1 "2019-03-07T18:07:37Z")

</div>

Hi

I need to create an event with multiple attendee via **code**. I got a collection “events” (date,title, attendees) with a multi-references field called “attendees” which refers to a collection of attendee (name, events).

What is the proper way to insert/save a new item in that collection?

I was hoping to be able to do something like that

```javascript
import wixData from 'wix-data';

let attendees = [attendee1._id, attendee2._id, attendee3._id] ;

let newEvent = {
  "date": new Date(),
  "title": "my event title",
  "attendees": attendees
};

wixData.insert("events", newEvent)
  .then(...)

```

1. is that the correct way? or is there a better way to do it?

2. should I also update the attendee collection field “events” to keep it sync?  
thx you

---

<div class="post-metadata">

**Author:** ![\_eric](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/_eric/32/994_2.png) [@\_eric](https://forum.wixstudio.com/u/_eric)\
**Post date:** [May 17, 2019, 2:04pm UTC](https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169/2 "2019-05-17T14:04:12Z")

</div>

Hi Quentin… did you ever receive any feedback on this? I have the same question and am looking for answers how to best utilize the multi-reference fields using the form elements and dynamic pages.

---

<div class="post-metadata">

**Author:** ![plomteuxquentin](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/plomteuxquentin/32/9345_2.png) [@plomteuxquentin](https://forum.wixstudio.com/u/plomteuxquentin)\
**Post date:** [May 17, 2019, 4:13pm UTC](https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169/3 "2019-05-17T16:13:39Z")

</div>

I ended up creating a joint collection (eventID, attendeeID) and do a bulk insert of attendees Id referencing 1 event. That suited better my use case and it bypass some limitation of multi referencement (like maximum 50 refs or something like that).

let me know if you need more help 🙂

---

<div class="post-metadata">

**Author:** ![tiaan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tiaan/32/896_2.png) [@tiaan](https://forum.wixstudio.com/u/tiaan)\
**Post date:** [February 23, 2020, 5:33am UTC](https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169/4 "2020-02-23T05:33:10Z")

</div>

Another solution to this problem:

```javascript
let headingArray = [];

export function buttonSubmit_click(event) {
headingArray.push(headingID)
let dataObj = {
"title": $w("#input1").value,
"shortDescription": $w("#textBox1").value
}
wixData.insert("Listings", dataObj)
.then((res) => {
let itemID = res._id;
wixData.insertReference("Listings", "heading", itemID, headingArray)
})
}

```

So this approach is quite straightforward. First, I create an array called headingArray, then I add some items to it via .push

Then I proceed to create an item in the database excluding the array items. When that item has been created, I get the \_id from the result and simply update that item with the array data by using insertReference

As I said, quite straightforward and works surprisingly fast.

Good luck!  
Tiaan

---

<div class="post-metadata">

**Author:** ![dalanyi](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/dalanyi/32/17439_2.png) [@dalanyi](https://forum.wixstudio.com/u/dalanyi)\
**Post date:** [October 8, 2020, 3:17pm UTC](https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169/5 "2020-10-08T15:17:40Z")

</div>

Hi Tiaan,  
Can You help me to answer what is “heading” and “Listings” in you straightforward approach, please!? I have to solve to insert member’s input into the reference field of my database called “top10jeloltek”, please!!!  
Thanks very much in advance!  
Laszlo

---

<div class="post-metadata">

**Author:** ![haydibaswedan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/haydibaswedan/32/13051_2.png) [@haydibaswedan](https://forum.wixstudio.com/u/haydibaswedan)\
**Post date:** [November 22, 2020, 11:15am UTC](https://forum.wixstudio.com/t/how-to-insert-item-with-multi-reference-field/16169/6 "2020-11-22T11:15:34Z")

</div>

@dalanyi[https://www.wix.com/corvid/reference/wix-data/insertreference](https://www.wix.com/corvid/reference/wix-data/insertreference)

those are the two databases

with regards to yours, top10jeloltek is one, and referenced with what database?

hope this helps
