【发布时间】:2020-04-25 00:04:29
【问题描述】:
我的产品结构是
product2: {
allAttributes: {
Color: ['black', 'silver'],
model: ["hero7"],
accessories: ["full travel kit", "2 batteries", "2 batteries + charger"],
brand: ["GoPro"]
}
category: ["camping"]
depositAmount: 1500
depositAmountTooltip: "Fully refundable security for this product."
displayrent: 650
expressDeliveryCharge: 200
id: "Ur89kjsllljVdQ8MM"
inventory: 5
keywords: (6)["Camping", "Outdoor", "Camera", "Electronic", "Gopro", "Action Cameras"]
longDescription: "longdescription"
name: "Gopro Hero 7 Black"
pictures: (3)[{
…}, {
…}, {
…}]
rank: 4501
subCategory: (6)["camping", "outdoor", "camera", "electronic", "gopro", "actioncamera"]
}
product1: {
allAttributes: {
Color: ['black', 'silver'],
model: ["hero8"],
accessories: ["full travel kit", "2 batteries", "2 batteries + charger"],
brand: ["GoPro"]
}
category: ["camping"]
depositAmount: 2000
depositAmountTooltip: "Fully refundable security for this product."
displayrent: 750
expressDeliveryCharge: 200
id: "Ur89kfksj1mVdQ8MM"
inventory: 5
keywords: (6)["Camping", "Outdoor", "Camera", "Electronic", "Gopro", "Action Cameras"]
longDescription: "longdescription"
name: "Gopro Hero 8 Black"
pictures: (3)[{
…}, {
…}, {
…}]
rank: 4500
subCategory: (6)["camping", "outdoor", "camera", "electronic", "gopro", "actioncamera"]
}
我正在查询它,
const {category, subCategory, color, brand } = req.query;
AllProductModel.where('category', '==', category)
.where('subCategory', 'array-contains-any', subCategory)
.get()
现在,我无法根据 color(req.query 中的数组) 和 brand(req.query 中的数组) 属性进行查询
如何根据从客户端选择的allAttributes 在 Cloud Firestore 上查询此类产品。我不想在客户端应用程序上这样做。
我正在使用“ReactJS”和“NodeJS,Express”。
【问题讨论】:
-
您是否已经尝试过?如果没有,我建议从firebase.google.com/docs/firestore/query-data/queries 开始。如果您已经这样做了,请编辑您的问题以包含minimum code that reproduces where you got stuck。
-
@FrankvanPuffelen 嘿,感谢您的帮助。我已经浏览了 firestore 上的查询文档。我想到的一种解决方法是在我的服务器上加载 3000-4000 个文档,然后在那里过滤它们。过滤后的文件然后发送到我的前端。这可能吗?或者它将在我的服务器上放置多少负载?
-
@FrankvanPuffelen 如果不是 Firestore,您会推荐哪个数据库?我目前正在使用 GAE 部署我的应用程序(前端和后端分开),我打算切换到 GCP 云功能。
标签: node.js reactjs google-cloud-firestore