I want to check the data is exist in a database. If suppose the data exist the value of k is set to 1
global.k = 0
va roll = {roll0:"1616",roll1:"234"}
for (let i = 0; i < inputcount; i++) {
var obj1 = roll["roll" + i];
const find = async() => {
const item = await RegisterUser.find({ eventname: event_name, rollno: obj1 })
if (item.length != 0) {
global.k = 1
console.log(global.k)
} else {
global.k = -1
console.log(global.k)
}
}
find()
}
console.log(global.k)
if(global.k==0){
// code for save
}
After if loop is executed, the value is not print as 1
or -1
.Actually, I think the problem is in async. Please help me