为什么这个Firebase".indexOn"不起作用?

Hug*_*Hou 7 firebase firebase-security firebase-realtime-database

所以我有这样的数据:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的代码中,我需要将下面的最新通知发送到某个"notifyId".这是代码:

ref.child('pushNotifications')
   .orderByChild("notifyId")
   .limitToLast(1)
   .on("child_added", function (snapshot) {
       console.log("Found a new notification...");
       sendPush(snapshot.val());
   });
Run Code Online (Sandbox Code Playgroud)

在我的firebase安全规则中,我有这个索引规则:

 "pushNotifications": {
      ".read": "auth != null",
      ".write": "auth != null",
      "$pushId": {
        ".indexOn": ["notifyId", "timestamp"],
      }
    },
Run Code Online (Sandbox Code Playgroud)

这是Firebase文档的索引结构:docs

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

FIREBASE警告:使用未指定的索引.考虑在/ pushNotifications中添加".indexOn":"notifyId"到您的安全规则以获得更好的性能

因为我已经这样做了,这没有任何意义.请帮忙!

Fra*_*len 25

你需要把.indexOn一级比你做的更高:

 "pushNotifications": {
    ".read": "auth != null",
    ".write": "auth != null",
    ".indexOn": ["notifyId", "timestamp"]
},
Run Code Online (Sandbox Code Playgroud)

为了进行比较,请始终查看有关索引Firebase文档,该文档使用此JSON示例:

"dinosaurs": {
  "lambeosaurus": {
    "height" : 2.1,
    "length" : 12.5,
    "weight": 5000
  },
  "stegosaurus": {
    "height" : 4,
    "length" : 9,
    "weight" : 2500
  }
}
Run Code Online (Sandbox Code Playgroud)

使用此索引规则:

{
  "rules": {
    "dinosaurs": {
      ".indexOn": ["height", "length"]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)