Javascript 数组包含的Firestore,如果为空则忽略
在我的每个文档上,我都有一个名为Javascript 数组包含的Firestore,如果为空则忽略,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,在我的每个文档上,我都有一个名为nameIndexes的数组,它是一个关键字数组,类似于: ["cat", "christmas", "tree", "topper", "decoration"] 然后我有一个搜索词数组,我通过执行where查询来查看它。但是我发现有人搜索数组中不存在的东西,结果是空的 我的搜索代码如下所示: this.ref = firebase.firestore().collection('designs').doc(firebase.auth().currentUse
nameIndexes
的数组,它是一个关键字数组,类似于:
["cat", "christmas", "tree", "topper", "decoration"]
然后我有一个搜索词数组,我通过执行where查询来查看它。但是我发现有人搜索数组中不存在的东西,结果是空的
我的搜索代码如下所示:
this.ref = firebase.firestore().collection('designs').doc(firebase.auth().currentUser.uid).collection('designs');
try {
searchArray.forEach(a => {
this.ref = this.designCollection.where("nameIndexes", "array-contains", a)
})
const designs = await this.ref.get();
designs.forEach(doc => {
let design = doc.data();
design.id = doc.id;
d.push(design)
})
} catch (e) {
message.error(e.message)
}
一些例子: 情景1 搜索词为
[“马”、“猫”]
它返回的文档的名称索引是[“猫”、“圣诞节”、“树”、“顶饰”、“装饰”]
场景2
搜索词为[“猫”、“马”]
没有发现任何结果
我在这里假设的是,在场景1中,它在数组中找不到马,因此转到cat并返回结果。在场景2中,它找到了猫,移动到马上,找不到它,所以什么也不返回
有没有一种方法可以使它返回查询匹配的所有结果?我能想到的唯一方法是执行单独的where查询,然后将所有结果推送到一个数组中,但是如果有多个搜索词,这将需要一段时间,并将负载添加到我的Firestore实例中我认为这在目前是不可能的,同时也在努力解决这个问题。。。