add elements to different databases from one form depending on database selection

I hope I can get some help as I have been scratching my head for days with this.

I am trying to build a form from which the user can add elements to different databases from a single form. Which so far I understand. But what I want is for the user to select which database in which the element will be loaded.

For example:
There are 5 video categories in total
the user would be able to upload a video to multiple categories from one form. But if he only selects 3 categories, the elements should only populate to the 3 databases selected in the selection box tool.

Which is the part I am struggling with. I can only manage to populate the element to every databases and not only the selected ones.

I hope this makes sense

many thanks

The problem with your idea is your database plan “probably”.

Because of you built your database system wrong “again probably” you can’t handle this easy category system.

Here is the video that I recorded for you with an example to show you how you can achieve this goal. But again “probably (%99)” you will need to create or edit your database/es.

Video (It’s a bit long but you will fix your problem %100): Video Upload Form For Selecting Any Amount Of Category For Each Video | Claap

Backend Code:

import wixData from 'wix-data';

const accessPermission = {
    suppressAuth: true
}

export function getCategories() {
    return wixData.query("VideoCategories")
        .find(accessPermission)
        .then((queryRes) => {
            const { items } = queryRes;

            if (items.length > 0) {
                return items.map((category) => {
                    return {
                        label: category.title,
                        value: category._id
                    }
                })
            }
        })
}

export function uploadVideo(videoData) {
    const selectedCategories = videoData.categories;
    delete videoData.categories;

    return wixData.insert("Videos", videoData, accessPermission)
        .then((createdVideoData) => {
            if (selectedCategories.length > 0) {
                selectedCategories.forEach(async (categoryId) => {
                    await wixData.insertReference("Videos", "VideoCategories", createdVideoData._id, categoryId)
                })
            }

            return createdVideoData;
        })
}

export function getVideoCategories(videoId) {
    return wixData.query("Videos")
        .include("VideoCategories")
        .eq("_id", videoId)
        .find(accessPermission)
        .then((queryRes) => {
            return queryRes.items[0]['VideoCategories'];
        })
}  

Frontend Code:

import { getCategories, uploadVideo } from 'backend/aModule.jsw';

$w.onReady(async function () {
    const categories = await getCategories();
    $w('#videoCategories').options = categories;

    $w('#uploadVideoButton').onClick(async () => {
        const video = {
            title: $w('#videoTitle').value,
            description: $w('#videoDescription').value,
            categories: $w('#videoCategories').value,
            views: 361782637812
        }

        const uploadedVideo = await uploadVideo(video);
        $w('#insertedVideoTitle').text = uploadedVideo.title;
    })
});

Test my example live: Video Example | My Site (exweiv.editorx.io)
Database Design: Video Database Design - dbdiagram.io