【发布时间】:2023-03-07 12:28:01
【问题描述】:
我正在尝试使用 array-contains 过滤我的 Firestore 中的两个不同字段,我看到较早的帖子说您不能使用两个 array- contains 在同一个查询中,但想知道是否仍然如此,或者有其他方法可以达到相同的结果吗?
我确实认为,也许做两个单独的查询,但两个字段都在同一个集合中,所以不确定这是否是最佳方式。
function getAllUserPlumb(){
var engineercounty = $('#engcounty').val();
console.log(engineercounty);
var docRef = db.collection("users");
docRef.where("trade", "array-contains", "Plumbing").where("engpostcode", "array-contains", engineercounty).get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// console.log(doc.data());
html = createEngineerRow(doc.data(),doc.id);
// $('#user_id').find('tbody').append(html);
});
});}
如果我结合使用 '!=' 和数组包含?
docRef.where("trade", '!=', ['Drainage', 'Gas & Heating', 'Glazing', 'Locksmiths', 'Pest Control', 'Electrical']).where("engpostcode", "array-contains", engineercounty)
【问题讨论】:
标签: javascript arrays google-cloud-firestore