Update/Insert in to two database collections?

Hello everyone,

I’m developing Wix site and have trouble inserting/updating records in two database collections, after “Submit” button is pressed. Let me explain my problem:
I have “Member profile” Dynamic page. On that page the logged user can add/modify user information, upload multiple images. For user information I have database collection called “MemberInfo”, for user images - database collection “MebmerImages”. The latter collection has reference field “Id” which coresponds to “Id” field in “MebmerInfo” collections. The relationship is One-to-Many - one user can have multiple images.
Here are my questions:

  1. How can I update data in “MemberInfo” collection and along with that insert record in “MemberImages”, after “Submit” button is pressed?
  2. What about the case, when the user fill the form for the first time and at the same time upload an image? In this case, I still don’t know the Id of the record in “MemberInfo” collection.
  3. I have another question - in the same page I want to show all images of the current user in a gallery element. If the user does not have image/s - nothing should be shown. If the user has image/s then, they must populate the gallery. After the user upload new image and submits it - the gallery must be refreshed. How can I achieve this functionality?

I have some backend dev experience with .NET language and I can code all of this in C#, but I’m new to frontend developing and Wix developing, in particular. I know that I should use Javascript to achieve what I want and I’ve searched a lot about my questions, but nothing seems to be shared about this particular topic. It turned into a vicious circle for me. So, I will be very grateful if someone can help me or explain to me what should I do.

Best regards!
Ivaylo

This is the update of my question:
This is my dynamic page “Users (ID)”:

And here is the code:

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixlocation from 'wix-location';// For full API documentation, including code examples, visit http://wix.to/94BuAAs

$w.onReady(function () {
    $w('#button3').onClick(function () { //#button3 is SUBMIT button ID
        let username = $w('#username').value;
        let email = $w('#email').value;
        let age = $w('#age').value;
        let eyecolor = $w('#eyecolor').value;
        let height = $w('#height').value;
        let weight = $w('#weight').value;
        let otherinfo = $w('#otherinfo').value;

        let userInfo = {
            "username": username,
            "email": email,
            "age": age,
            "eyeColor": eyecolor,
            "height": height,
            "weight": weight,
            "additionalInformation": otherinfo,
            };

    wixData.save("Users", userInfo)
        .then( (results) => {
            let userItem = results; 

            if($w("#uploadButton2").value.length > 0) {
                let image = $w("#uploadButton2").value;
                let userImage = {
                    "image": image,
                    "userId": userItem['_id'],
                };
                wixData.insert("UserImages", userImage)
                .then(() =>{
                    wixlocation.to('/Users/${wixUsers.currentUser.id}')
                })
            }
                } )
        .catch( (err) => {
            let errorMsg = err;
        } );


    })
});



But this code doesn’t work. Nothing is inserted/updated in the database collections!
`I hope someone can now tell me where are my errors in the code/structure!

Hi,

Can you provide the url of your published site, or alternatively your Wix user name and the site name ?

Thanks,

Itay