What I’m trying to do is to find a way to query user-data(username, email, bio) related to the ethAddress/accounts.
Right now my user and user-data are two different classes and I’m trying to find a way to link/join them so I can query the correct user-data.
Code to set data:
//saving user data
async function savebtn(){ const UserData = Moralis.Object.extend("UserData"); const currentUser = new UserData(); currentUser.set("UserName", username.value); currentUser.set("Email", email.value); currentUser.set("Bio", bio.value); const fileUploadControl = document.getElementById("picfile"); if (fileUploadControl.files.length > 0) { const file = fileUploadControl.files[0]; const name = "profile_pic.jpg"; const profilePic = new Moralis.File(name, file); currentUser.set('profile_pic', profilePic); } currentUser.save().then((currentUser) => { window.location.href = "profile.html"; }, (error) => { alert('Error: ' + error.message); }); }
Code to query data:
//querying userdata
const UserData = Moralis.Object.extend("UserData"); const query = new Moralis.Query(UserData); query.get(Moralis.User).then((UserData) => { const profilePic = UserData.get('profile_pic'); document.getElementById('picimg').src = profilePic.url(); const username = UserData.get('UserName'); document.getElementById('username').innerHTML = username; const bio = UserData.get('Bio'); document.getElementById('bio').innerHTML = bio; });
This code gets data for all users, which is not what I want to do.
So far I’ve tried adding ethAddress/accounts column in user-data but it displays an empty string with no error in console.
I’ve tried using aggregate pipeline lookup no success.
I am not that proficient in queries in general and I am going through the cloud functions and also Aggregate in detail to see what can I get. But if someone could tell me what am I doin wrong or where do I need to look that’d be super helpful. Thanks.