New members not updated in collection using wix-code

Hello,

I am using the following code below to create a member-profile log.

.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Membership”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Membership”, toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button3”).label = “Logout”;
$w(“#button2”).show();
} )
.catch( (err) => {
console.log(err);
} );
}
}

export function button2_onclick() {
wixLocation.to(/Membership/update/${wixUsers.currentUser.id});

It seems that each new members created are not updated in the collection and there seems to have no error messages to indicate the issue. All data and permissions are set accordingly, but no new URL is created to assign a unique ID in the collection. It would be great to understand the issue behind this matter. Thanks for your concern.

Hi,
I guess some code is missing,
Add the code from here .
If it’s still doesn’t work, please paste here your url so we can inspect.
Roi

Hi Roi,

Many thanks for your reply. My website is now live https://www.qryptominingtrade.com/buysell .

In the preview mode, I see the following errors:

Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.Loading the code for the BUY/SELL page. To debug this code, open y7jij.js in Developer Tools.Not Found (404) - The requested resource could not be foundno data matched this query: {“$and”:[{“_id”:{“$matches”:{“ignoreCase”:true,“spec”:[{“type”:“literal”,“value”:“1fc9fd95”},{“type”:“anyOf”,“value”:" -“},{“type”:“literal”,“value”:“dd20”},{“type”:“anyOf”,“value”:” -“},{“type”:“literal”,“value”:“4ac9”},{“type”:“anyOf”,“value”:” -“},{“type”:“literal”,“value”:“b04e”},{“type”:“anyOf”,“value”:” -"},{“type”:“literal”,“value”:“7d2f868e3e24”}]}}}]}, with the pattern: /Update/{_id}Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.Loading the code for the BUY/SELL page. To debug this code, open y7jij.js in Developer Tools.

I hope you can detect the reasons. Many thanks in advance.

Kind regards,

Quyen Nguyen

Hi,
I can’t reproduce this error.
But i see you have a permission issue.


You need to change to “Anyone” in "Who can create content for this collection ? " section. a non site member needs permission to create content to the members database collection.
Good luck!
Roi

Hi Roi, Thanks for your help. It works.

Kind regards,

Quyen Nguyen