Can I get access to the internal ID field in a database collection. I have around 1400 entries in a CSV file that I plan to load into a custom database. The primary key of the old database used a numeric Member_ID field. I would like to use this same value for the WIX default ID field. Is this possible?
yep.
Each element in our database has an _id property. On insert, if _id is available we will use it as the id. If not, we will generate an _id.
Please note that the _id has to be a string.
So, if I simply change the top line of my CSV FILE from “member_id” to “ID” it should load ok as in CSV format , each field would be enclosed in double quotes and separated by a comma.
ID,Fname,Middle,Lname…
“12345”,“Jerry”,“D”,“Smith”… and so on…
Right? And just to be sure before I load up my data, should the field name be, “_id”, “id”, or “ID”?
Hi,
Yes, it should work.
The field is named ‘_id’.
You can also leave it out completely and the import wizard will generate a unique ID for you.
I need to use my value as that establishes a relationship to another table
Hey,
You can reference other DB collection using Reference Fields .
Best,
Tal.
Hi, is it possible to start with an _id of 1 and increment with 1 each time a form is submitted (onClick)?
Hi Daniel,
Are you using a “Submit” action of a button of code ?
Roi
Also looking for way to tie databases together, without using reference fields. https://www.wix.com/code/home/forum/community-discussion/tying-two-databases-together-with-common-field-for-filtering-datasets-but-without-manually-entering-data-to-those-fields
Can we generate unique id in wix database like we received id ccc629b6-461b-4be7-96d5-edaf13632220 like that and i need to 657-123-564 like my dynamic id https://www.gazette.international/member-profile/ccc629b6-461b-4be7-96d5-edaf13632220 The URL should be: https://www.gazette.international/ then 9 random digits, like this: https://www.gazette.international/045-768-476
You can get a “unique” nine character id like this:
let id = Math.random().toString(36).substr(2, 9);
If you want just numeric digits:
let id = Math.random().toString(10).substr(2, 9);
As with any random function, there is a very small chance of duplicates. The guids generated by the Wix database are unique.
@yisrael-wix as i use above code in my site but didn’t get any output check below screenshot, id format did not change as i want https://www.gazette.international/MemberProfile/6ebafba6-9af0-465a-b02d-84dafc7d4527