我正在嘗試使用 firestore 的 .where() 功能來檢測某個字符串是否在數據庫中的數組中。我嘗試通過添加括號和其他東西來表示數組的一部分來操縱函數的第一個參數,但無濟于事。//in this section I am getting the "yourLikes" integer (unrelated to the problem)var liks = [];var tempLiks = []db.collection("users").where("uid", "==", uid).get().then(function(querySnapshot) { querySnapshot.forEach(function(doc) { tempLiks = doc.data().yourLikes; // I am using a setTimeout() function to allow firebase to // process the previous query and give me the doc.data().yourLikes for tempLiks setTimeout(function(){ //Right here, the "usersLiked" data is an array, with a bunch of different values. // I am trying to see if one of those values is doc.data().uid from my previous query. (I think) this is the problem. db.collection("memeInfo").where("usersLiked", "==", doc.data().uid) .get() .then(function(querySnapshot) { querySnapshot.forEach(function(doc) { for (var i = 0; i < tempLiks.length; i++) { liks.push([tempLiks[i],doc.data().likes]) console.log(liks) } }) }) },500)如果有人有一個解決方案來查詢單個值是否在數組中而不永遠使用 for 循環(我可能在 usersLiked 數組中有數千個值),那將不勝感激。
火店難題!將 .where() 用于數組和字符串
慕容森
2021-06-07 10:25:02