I'm trying to modelise a system with user-item databases. User has a field pointing on item id. But I can't use the item._id as primary key ... So, as mentionned sometimes in this forum, I decided to use the item._id to fill an other field as primary key, item.my_id.
So I insert my item using wixData.insert then it returns the item filled with _id (and other fields hidden in the database).
Then, I try to get my newly inserted item with wixData.get, updating the field my_id = _id then update it in base using wixData.update.
It works. 9 times out of 10. Sometimes, wixData.get("MyDatabase", item["_id"]) returns null object in the Promise, it looks like the item isn't inserted yet, but I have an _id .... No sense, I don't know with it fails randomly.
I tried an other trick using database hooks and after_insert,
item.my_id = item._id;
from the API, but it doesn't do anything. My_id still empty. (see here : https://www.wix.com/corvid/reference/wix-data.Hooks.html#afterInsert )
Is there something wrong with dabases and wix ??? Am I doing bad code ? New with JS but Python expert. I can push my code below to be more understandable.