我正试图使用array-contents过滤Firestore中的两个不同字段,我看到以前的帖子说你不能在同一个查询中使用两个array-contens,但我想知道情况是否仍然如此,或者有其他方法可以获得相同的结果吗?
我确实认为,也许可以进行两个单独的查询,但两个字段都在同一个集合中,所以不确定这是否是最佳方式。
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)
我有一个可能的解决方案。
function getAllUserPlumb(){
var engineercounty = $('#engcounty').val();
// console.log(engineercounty);
var docRef = db.collection("users");
docRef.where("engpostcode", "array-contains", engineercounty).get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
if(doc.data().trade.includes('Plumbing') ){
// console.log(doc.data());
html = createEngineerRow(doc.data(),doc.id);
// $('#user_id').find('tbody').append(html);
}
});});}