How do you write successfully to reference fields in a collection using Velo code?

I am trying to write the name of an organisation to a collection (called Posts) so that I can later pull the logo for that organisation, which is stored in another collection (called MemberOrgs).

I have written code to pull the user’s ID so I can identify the user’s email address, which I can use to identify their organisation…and populate it into the “Posts” collection, in the referenced field.

The code seems to be working fine except I get this in the collection when I am done:

Am I missing something about how referenced fields work or is their something I need to be aware of when writing to a Reference field in a collection using Velo? I’ve read everything I can find in the API docs but I am not getting any closer to being able to answer this one myself…so I am hoping someone can shed some light on this.

You have to insert the _id of the referenced field, not the value of the primary field.

@jonatandor35 Sorry…I don’t quite understand what you’re saying. Can u clarify?

Simon.

@simon9978 Let’s say you have 2 collections: Users and Addresses.
The Users collection has the fields: _id, name, email and address (the address field is a reference that links to the Addresses collection).
The Addresses collection has the fields: _id, address

Now if you wish to assign an address to user, you take the _id value of the address (as appears in the Addresses collection) and insert it to the address field in the Users collection

That worked perfectly. It’s not how referencing works in any other database I have used but, as long as it is consistent here, that is great. Very much appreciate the clarification.

:+1: