I'm trying to retrieve the _id field with Wix Velo of my logged in user. The code is working, however the function I'm using is returning [object Promise] instead of the id string that I need.
import wixData from 'wix-data';
export function getID() {
return wixData.query("Picks") // My Collection
.eq("player", "Gary") // A field, and a cell
.find()
.then((results) => {
if (results.items.length > 0) {
let firstItem = results.items[0]._id;
console.log("Return ID: " + firstItem) // This returns the ID I need
$w("#text31").text = firstItem;
// return firstItem.toString();
} else {
console.log("No Items Found")
}
})
.catch((err) => {
let errorMsg = err;
});
}
console.log("Return the ID outside of the function: " + getID()) // This returns "[object Promise]"
I've tried to use await, but it just gives me errors.