Return data from query outside scope

I want to see if there is a way to call a query and return a specific value to use later.
Ex:
let isPollRunning = false;
isPollRunning = wixData.query(“IsPollRunning”)
.find()
.then((results) => {
console.log("Poll is currently " + results.items[0].open)
return results.items[0].open;
})
.catch((err) => {
let errorMsg = err;
console.log(err);
});
console.log(isPollRunning)
inside the query it will send the correct value to the console, however if when it gets to the second console.log it displays a promise object instead of the desired boolean value.

Hi Aaron,

All you need to do is saved the value from inside the promise callback:

let isPollRunning = false;
wixData.query("IsPollRunning")
	.find()
	.then((results) => {
		isPollRunning = results.items[0].open;
	})
	.catch((err) => {
		let errorMsg = err;
		console.log(err);
	});

Note that this may cause a problem if you try to read the value of “isPollRunning” before it is resolved.
If you want to make sure you get the correct value from the database, you must wait for it.