gpt4 book ai didi

javascript - 数组包含未获取二维数组中的结果

转载 作者:行者123 更新时间:2023-12-02 20:55:51 24 4
gpt4 key购买 nike

我正在将数据保存在如下图所示的文档中。我想从数组 notifyArrayctg 中获取记录,其中 array-contains Burger

这是我正在尝试的代码:

  firebase.firestore().collection(`notifications`)
.where("notifyArray", "array-contains", 'Burger')
.onSnapshot(querySnapshot=> {
querySnapshot.forEach(doc=> {
console.log(doc.data());
console.log("Search result");
var data = Object.assign(doc.data(), {docid : doc.id})
this.goalList1.push(data);
});
console.log(this.goalList1);
});

但它没有返回任何结果。理想情况下它应该返回 2 条记录。

enter image description here

最佳答案

数组notifyArray是一个映射数组,每个映射包含两个属性。 Firestore 不支持查询数组中的 map 属性。您只能搜索 map 的全部内容,这意味着您必须知道其所有字段的所有值。

您可以做的是创建一个新数组,其中包含 map 中 food 属性的字符串值,然后查询该数组。

firebase.firestore()
.collection(`notifications`)
.where("foodArray", "array-contains", 'Burger')

上面,查询期望有一个名为 foodArray 的字符串数组。

关于javascript - 数组包含未获取二维数组中的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61487237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com