I’m developing a website where members can upload a document. I created “members” collection which have a field called “fileUploaded” of type “document”. If registered member trying upload document, i’m saving in this field. If user accidentally updated wrong file or wanted to upload another file, i need to save previously updated file also. For this purpose i created “UserDocuments” collection which can hold “memberID” and “fileUploaded” from “members” collections.
To simplify, I need to save all the file(s) updated by members in a new collection where i filter or query by “Member ID” later. For this purpose I’m trying to use Hooks concepts on “members” collection after update. Can anyone help me on how to insert record into “UserDocuments” collection on updating members collection “fileUploaded” field.
I need to insert into “UserDocuments” collection only if “fileUploaded” field is updated in members collection.
import wixData from ‘wix-data’;
export function members_afterUpdate(item, context) {
// Code sample needed : to insert into UserDocuments Collection if fileUpload is changed
Hi,
Maybe you should try another approach, instead of connecting the upload to the data base, create an onClick event or any other event you can use, use query to check whether the user already uploaded an item, based in the answer use insert to insert the data to the relevant database.
check out the following:
You didn’t use query to insert the data to the right database…
check whether the member already uploaded a file, if he did insert to the “userDocuments” database and if he didn’t insert to the “members” database.