Ive tried the following code to query and insert into 2 db’s, however it only inserts into 1?
.then((user) => {
userId = user.id;
return user.getEmail();
})
.then((email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query("ApproveApplication") &&("MemberProfile")
.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
};
Promise.all([
wixData.get("ApproveApplication", userId),
wixData.get("MemberProfile", userId)
])
.then(r => {
if(!r[0] && !r[1]){
//in case it doesn't appear in both collection, write here what to do
}
})
You’ll need to try location the problem.
add .console.log() with the relevant data to every step + add return before the wixData.insert + add .then(r => console.log(r)) after the insert(), and try to figure it out.
Hi JD still no luck buddy, i’m actually unable to preview the login and get an error code because i use the standard wix login feature and not a custom page, i tried the above but still didnt work
Hi Jd ive managed to get it working to a degree off a register success lightbox and not the site code above, it inserts into 2 databases the same id’s and owner id’s however it seems when first registering it also adds an Owner user Id automatically to the backend, and Members/PrivateMemberData, so because im using two different datasets linked to 2 buttons within the members area that are both filtered to owner is logged in, whats happening is the 1 dataset linked to the first db is pulling the original signup Id and not the one being inserted
register success lightbox code
import wixSite from 'wix-site';
import wixLocation from 'wix-location';
import wixData from 'wix-data';
import wixUsers from 'wix-users';
let usrID;
$w.onReady(function () {
let registerSuccessBox = wixSite.currentPage;
});
export function lightbox1_viewportEnter(event) {
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then((email) => {
let userEmail = email; // "user@something.com"
// create an item
const toInsert = {
"_id": userId,
"email": userEmail
};
//in case it doesn't appear in both collection, write here what to do
wixData.insert("ApproveApplications", toInsert)
.then((results) => {
let item = results;
})
.catch((err) => {
let errorMsg = err;
});
wixData.insert("MemberProfile", toInsert)
.then((results) => {
let item = results;
})
.catch((err) => {
let errorMsg = err;
});
})}
export function proceedButton_click(event) {
wixLocation.to(`/account/my-account`);
}
Here you can you see the id at the bottom of page when hovering over My Profile button