gpt4 book ai didi

firebase - 为什么此Firebase ".indexOn"不起作用?

转载 作者:行者123 更新时间:2023-12-04 09:10:39 25 4
gpt4 key购买 nike

所以我有这样的数据:

pushNotifications {
-K - RwEgd541PIGNOXXUH: {
message: "Xiaoyu Hugh Hou bid at $900 on your task: New P..."
notifyId: "facebook:10100683829966199"
relatedTask: "-Jzl8XKaxGCv19nIOChm"
timestamp: 1443594566599
} - K - RwpcBlQa04VJT4Bwm: {
message: "Sam Feldt bid at $1100 on your task: New Post g..."
notifyId: "google:1043268349966197"
relatedTask: "-Jzl8XKaxGCv19nIOChm"
timestamp: 1443594721963
} - K - RwuM3 - 0 G0q9I96WHg: {
message: "Sam Feldt bid at $600 on your task: NO Firebase..."
notifyId: "facebook:10100683829966199"
relatedTask: "-JzTSk2TIlO46oVqJ1Nn"
timestamp: 1443594741347
}
}

在我的代码中,我需要将下面的最新通知发送给某个“notifyId”。这是代码:
ref.child('pushNotifications')
.orderByChild("notifyId")
.limitToLast(1)
.on("child_added", function (snapshot) {
console.log("Found a new notification...");
sendPush(snapshot.val());
});

在我的Firebase安全规则中,我具有以下索引规则:
 "pushNotifications": {
".read": "auth != null",
".write": "auth != null",
"$pushId": {
".indexOn": ["notifyId", "timestamp"],
}
},

这是Firebase文档在此处遵循的索引结构: docs

但是当我运行代码时,控制台仍会记录

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "notifyId" at /pushNotifications to your security rules for better performance



自从我这样做以来,这没有任何意义。请帮忙!

最佳答案

您需要将.indexOn比您执行的操作高一级:

 "pushNotifications": {
".read": "auth != null",
".write": "auth != null",
".indexOn": ["notifyId", "timestamp"]
},

为了进行比较,请始终查看 Firebase documentation on indexes,它使用以下JSON示例:
"dinosaurs": {
"lambeosaurus": {
"height" : 2.1,
"length" : 12.5,
"weight": 5000
},
"stegosaurus": {
"height" : 4,
"length" : 9,
"weight" : 2500
}
}

使用此索引规则:
{
"rules": {
"dinosaurs": {
".indexOn": ["height", "length"]
}
}
}

关于firebase - 为什么此Firebase ".indexOn"不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32860141/

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