Currently utilizing async-await:
Whenever the function run invokes findLateastVersion
, even though run function is marked as async, an error message pops up stating await is a reserved word
. The findLateastVersion
method returns a promise and based on various tutorials, everything should be in working order. So, why does this pesky error persist?
async function findLateastVersion(surveyName, db) {
return new Promise((resolve, reject) => {
try {
const refv = await db.collection('surveys').doc(surveyName).collection('versions').orderBy('timestamp'); //reference to specific version docs
console.log(refv);
let docName = refv.firebase.firestore.FieldPath.documentId();
resolve(docName);
// const versions = refv.where(firebase.firestore.FieldPath.documentId(), '!=').orderBy("timestamp").limit(1);
} catch (err) {
console.log('err: ', err);
}
reject("error")
});
}
async function run() {
const db = await connectToFirestore();
const surveyName = argv.s || argv.surveyName;
const surveyVersion = argv.v || argv.surveyVersion;
const names = ['a', 'b', 'c'];
if (!surveyName) {
names.forEach(async function (surveyname) {
console.log("surveyname", surveyname)
const version = await findLateastVersion(surveyname, db)
//getSurveyData(surveyname, version, db);
});
}
//await getSurveyData(surveyName, surveyVersion, db);
}