Can the _id in my database have the same value as the _owner?

Is it possible to make the value of “_id” in my database the same as the “_owner” so that the link below will work properly? Here is my website: https://www.raqiya-aviation.com/

wixLocation.to(`member/my-profile/${wixUsers.currentUser.id}`)

Hello again,
sorry but i do not really understand your issue. What are you trying to do ?

Id can be programmed, for example:
let toSave = {
// “_id”: “1”,
“_id” : $w( “#input14” ).value,

I assumed you need to filter by the owner. If this is the case, you can add a filter the collection in your form or query to the owner only.

Hi again russian-dima! :grin:

In my sign up page, I want to add a code wherein the value of _id will be the same value as the _owner in my own database because the ID at the end of the page url is _owner and not the _id of my database.


Every time I use this code for example: wixLocation.to(/Members/${ wixUsers.currentUser.id } )
it directs me to 404 page because the wixUsers.currentUser.id is not the same as the _id but _owner.

This is part of my code in the sign up page.

function registerPerson() {

 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#firstName").value;
 let last = $w("#lastName").value;
 let userId = wixUsers.currentUser.id;  

 wixUsers.register(email, password, {
   contactInfo: {
 "firstName": first,
 "lastName": last
   }
  })

 .then(() => {
 let toSave = {
 "emailAddress": email,
 "password": password,
 "firstName": first,
 "lastName": last,
    };
    wixData.save("MemberPage", toSave)
    })

    .then(() => {
       $w("#successful").show();
       wixLocation.to("/member/welcome-new-user");
 //Change the URL ending to the page you want to redirect the user after they successfully register
  })

I hope you get what I mean and thanks a lot!

Additional to shimonsuissa1954-advise, you could also manipulate the location where you want to direct to as you want…

Just as little example here…

https://russian-dima.wixsite.com/meinewebsite/create-my-link

This shall just show you, that you can manipulate your url as you want :wink:.

So get the current users-informations…

import wixUsers from 'wix-users';
2
3// ...
4
5let user = wixUsers.currentUser;
6
7let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
8let isLoggedIn = user.loggedIn; // true
9
10user.getEmail()
11  .then( (email) => {
12    let userEmail = email;      // "user@something.com"
13  } );
14
15user.getRoles()
16  .then( (roles) => {
17    let firstRole = roles[0];
18    let roleName = firstRole.name;                // "Role Name"
19    let roleDescription = firstRole.description;  // "Role Description"
20  } );
21
22user.getPricingPlans()
23  .then( (pricingPlans) => {
24    let firstPlan = pricingPlans[0];
25    let planName = firstPlan.name;          // "Gold"
26    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
27    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
28  } );

Choose the data of the user which you need.
Get your location.to …
(/Members/${wixUsers.currentUser.id})
Modify it in similar way like shown in example and do what ever you want with your own generated/manipulated LINK/URL/LOCATION what ever.

It looks like you are trying the original Wix tutorial method they released in 2017.

If you follow Wix’s tutorial you will be able to accomplish what you need. You may need to modify the insert just a tiny bit as you want to save more data than shown in their example.

I must warn you though, should you attempt to use Wix’s tutorial method ---- there is a small chance that a ‘verify your email’ message may automatically be triggered by Wix even if you dont code it. It may or may not show up radomly, but when it does ---- it will break your registration process therefore your ‘insert’ code may never be triggered. (I provided this feedback to Wix a few months ago. Not sure what their plans are for this. Because of it ---- it is difficult to create a custom registration process without added limitations for fear that the registration flow will break.)

You might also want to consider using the Members Area pages as it involves less code. (You can find several tutorials on YouTube for this.)

Thank you very much for replying russian-dima, Code Queen Nayeli, shimonsuissa1954… I really appreciate it! :grin:

Actually, I based my code to this youtube link: https://www.youtube.com/watch?v=o1gc-baNMrY&t=429s
Thanks to Code Queen Nayeli!

And added a let toSave code inside the function registerPerson().
Thanks to russian-dima!

This is the whole code of my sign up lightbox. I believe I will put the additional code inside the function registerPerson(), but I don’t know where and what code exactly to put there that could insert the contactId , which is in the PrivateMembersData, to the _id inside my own database.

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
let registration;

$w.onReady(function () {

 if (wixUsers.currentUser.loggedIn) {
  wixLocation.to(`/member/my-profile/${wixUsers.currentUser.id}`);  //Change the URL ending to the page you want to redirect the user if they are already logged in
 }

 $w("#password").onKeyPress((event) => {
 let key = event.key;
  $w('#errorMessage').hide();
  $w('#emailExists').hide();
 if (key === "Enter") {

   console.log("Pressed Enter key on Password field"); //You can change the text of this line or delete it

 if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#firstName").value;
 let last = $w("#lastName").value;

    wixUsers.register(email, password, {
      contactInfo: {
 "firstName": first,
 "lastName": last
      }
     })
    .then(()=>{
      $w("#successful").show();
       wixLocation.to("/member/welcome-new-user")
//Change the URL ending to the page you want to redirect the user after they successfully register

    .catch((err) => {
 let errMsg = err;
    });
    })
     .catch((err) => {
 let errorMsg = err;
      console.log(errorMsg);
      $w('#emailExists').show();
     });
   } else {
    console.log("Some inputs are invalid"); //You can change the text of this line or delete it
    $w('#errorMessage').show();
   }
  } else {
   console.log("Did not press Enter key."); //You can change the text of this line or delete it
  }
 });

 $w("#registrationButton").onClick((event) => {
  console.log("Button was clicked"); //You can change the text of this line or delete it
  $w('#errorMessage').hide(); //We want to hide all error messages when the person attempts to register again
  $w('#emailExists').hide(); //We want to hide all error messages when the person attempts to register again
 if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
   registerPerson();
   console.log("Trying to register"); //You can change the text of this line or delete it
  } else {
   $w('#errorMessage').show(); //This is were we prompt the message to show up again ONLY if there is an error
   console.log("Missing information"); //You can change the text of this line or delete it
  }
 });
});

function registerPerson() {

 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#firstName").value;
 let last = $w("#lastName").value;
 let userId = wixUsers.currentUser.id;  

 wixUsers.register(email, password, {
   contactInfo: {
 "firstName": first,
 "lastName": last
   }
  })

 .then(() => {
 let toSave = {
 "emailAddress": email,
 "password": password,
 "firstName": first,
 "lastName": last,
    };
    wixData.save("MemberPage", toSave)
    })

    .then(() => {
       $w("#successful").show();
       wixLocation.to("/member/welcome-new-user");
 //Change the URL ending to the page you want to redirect the user after they successfully register
  })

  .catch((err) => {
 let errorMsg = err;
   console.log(err);
   $w('#emailExists').show(); //This is were we prompt the message to show up again ONLY if there is an error
  });
}

And added a let toSave code inside the function registerPerson().

Thanks to russian-dima!

No, i think the THX goes to —> shimonsuissa1954 :sweat_smile:

I added that code even before I posted this… and I got that code from the one that you sent me recently (about the chatbox). :sweat_smile:

@aeroengineerz7 ahhh!!! Glad a video help you out!!

Alright — so let’s look at your code then. It’s just a matter of putting things in the right place so that the logic is correct.

You have a password on keypress, but then you also have a register button on click event but they are doing 2 different things and neither of them have the Owner ID saved into the database.

At the beginning of your code you have a redirect to a dynamic page with the user ID. This code will not work if you did not capture the user ID during the registration.

So lets add the missing logic to make sure our code captures the missing information and triggers things in the correct order. I added more notes on a few lines.

(Notice that I left out the password in the database insert, as this is not good practice to save user’s credentials. P.s. Sharing your entire code vs partial code helps the community understand the full picture when helping someone to troubleshoot.)

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
let registration;

$w.onReady(function () {

 if (wixUsers.currentUser.loggedIn) {
        wixLocation.to(`/member/my-profile/${wixUsers.currentUser.id}`); //Change the URL ending to the page you want to redirect the user if they are already logged in
    } else {
        console.log("User was not logged in when they arrived here.")
    }

    $w("#password").onKeyPress((event) => {
 let key = event.key;
        $w('#errorMessage').hide();
        $w('#emailExists').hide();
 if (key === "Enter") {

            console.log("Pressed Enter key on Password field"); //You can change the text of this line or delete it

 if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
 //registerPerson();  //You can delete all the other lines and simply trigger the registerPerson function so that you have less code here
 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#firstName").value;
 let last = $w("#lastName").value;

                wixUsers.register(email, password, {
                        contactInfo: {
 "firstName": first,
 "lastName": last
                        }
                    })
                    .then((user) => {
 let userId = user.id; //after the person is registered we get their user ID

 const toInsert = {
 "emailAddress": email,
 "firstName": first,
 "lastName": last,
 "_id": userId,
                        };
 // add the item to the collection
                        wixData.insert("MemberPage", toInsert)
                            .then(() => {
                                $w("#successful").show();
                                wixLocation.to("/member/welcome-new-user");
                            })
                            .catch((err) => {
 let errMsg = err;
                                console.log("A record with a matching ID already exists, or user does not have permission to insert into this collection.");
                            });
                    })
                    .catch((err) => {
 let errorMsg = err;
                        console.log(errorMsg);
                        $w('#emailExists').show();
                    });
            } else {
                console.log("Some inputs are invalid"); //You can change the text of this line or delete it
                $w('#errorMessage').show();
            }
        } else {
            console.log("Did not press Enter key."); //You can change the text of this line or delete it
        }
    });

    $w("#registrationButton").onClick((event) => {
        console.log("Button was clicked"); //You can change the text of this line or delete it
        $w('#errorMessage').hide(); //We want to hide all error messages when the person attempts to register again
        $w('#emailExists').hide(); //We want to hide all error messages when the person attempts to register again
 if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
            registerPerson();
            console.log("Trying to register"); //You can change the text of this line or delete it
        } else {
            $w('#errorMessage').show(); //This is were we prompt the message to show up again ONLY if there is an error
            console.log("Missing information"); //You can change the text of this line or delete it
        }
    });
});

function registerPerson() {

 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#firstName").value;
 let last = $w("#lastName").value;

    wixUsers.register(email, password, {
            contactInfo: {
 "firstName": first,
 "lastName": last
            }
        })
        .then((user) => {
 let userId = user.id; //after the person is registered we get their user ID

 const toInsert = {
 "emailAddress": email,
 "firstName": first,
 "lastName": last,
 "_id": userId, //yes, the _id and the _owner can be the same value
            };
 // add the item to the collection
            wixData.insert("MemberPage", toInsert)
                .then(() => {
                    $w("#successful").show();
                    wixLocation.to("/member/welcome-new-user");
                })
                .catch((err) => {
 let errMsg = err;
                    console.log("A record with a matching ID already exists, or user does not have permission to insert into this collection.");
                });
        })
        .catch((err) => {
 let errorMsg = err;
            console.log(errorMsg);
            $w('#emailExists').show();
        });
}

Thank you very much for helping me with this one Nayeli! :blush:

I already tried your code. The email, first and last name, are now inside my own database (MemberPage), but unfortunately, the _id in that database still didn’t match with the _owner which has the same value as the contactId in the PrivateMembersData. So in this case, I cannot open My Profile Page which has a link as shown in the right side of the picture.


So this is the reason why I wanted to make the _id have the same value as the _owner or contactId

Hi Nayeli!

Do you have any other solution for this one? I still can’t solve it. :sob: