Using ID instead of Title (or other field) as Primary Field

When I create a new collection and add a reference field I am only allowed to select and item by the Primary Field. Usually this would be the ID, but in the case of Wix it seems to be any field other than the ID. This causes some problems as I have to manually make sure I keep the Primary Field unique… I would prefer to use the ID field as it will always be unique. Is there a simple work around?

It would neat if I could reference an item by the Title (like it is already) and then it would automatically add the referenced item’s ID into an adjecent field…

Any help would be much appreciated.

This issue has been raised before on this very forum. You are right, it is a bit strange. From memory, the workaround was to just copy the _id field to another (second id) field and use that one as a ref. It´s rather safe, since the id never changes.


Thank you for the response. This seems to be the way to do it.

Giri Zano How do I copy the _id field to another (second id) field and use that one as a ref. When I try, I get an error saying “field ‘id’ already exists”. I just want to be able to create a field that auto-generates so that there are no duplicates and that can be accessed for querying. Can you help or point me in the right direction. I am coming from PHP and this is a pretty standard thing. Any help would be greatly appreciated.

If you show me the code I could likely tell you for sure, but from the error it sounds like you simply need to change the name of new field. For example, If I have a collection of photos named Pictures, I would name the new ID field as pictureID. Once this new field is constructed on the backened, you will see it in the collection and then you will need to right click the new field or colum and select “Add field to schema”. Once the new field has been added you will now be able to right click it again and select “Set as Primary Field”. The backend code would look something like this…

export function Pictures_afterQuery(item,) {
item.pictureID = item._id;
return item;


If you have yet to construct any backend code, simple go to the collection / dataset and click the “Hooks” option. This should create a backend file called data.js - click on that file and add the code.

1 Like
Hello, I tried your code and it works, the problem is that if I want to create a dynamic item page, the entire row is blank. But... if you manually modify the empleoID entry in database, the dynamic page link appears in database . any solution?