Can't update multi-reference field in Collection

I’m trying to save an array of the referenced collection ids as strings for my multi-reference field, but when it saves, the field in the database is left empty

This is the code structure I am using. The field key is ‘sessions’ and it is set up as a multi-reference


 console.log(sessions); // ['<id>','<id>']
 const camp = {
            '_id': campId,
            title: title.value,
            sessions: sessions,
        }
 await wixData.save('Camps', camp)
 .then(item => {
            console.log(item.sessions); //undefined
 );
   

Inside the ‘Camps’ collection:

How am I supposed to update or save multi-reference fields for the collections? Are they not arrays of id strings as it says in the documentation?

did you ever find an answer to this?

No, I quit trying to use this api and approach since the mutli-reference never worked for me. Instead I just made the connections from the smaller items so I query for them etc. The multi-reference api was awful and I’d recommend ignoring it completely

Instead do it from one side. So for my example I had Camps that had multiple Camp Sessions, so instead of a multi-refrence in the Camps collection AND a camp reference in the Camp Sessions collection—I just have the later, and Camps themselves don’t have any lists of their connected items at all

Whenever I need a Camp Session I query for Camp Sessions who’s Camp reference is the Camp id I am looking for. This also works better for repeaters elements etc.

I am about to rip apart my design and do the same exact thing. Thanks for the quick reply :slight_smile:

I used insertReference()…

await wixData . insertReference ( “Collection” , “ReferenceField” , itemId , referenceArray , options )