【问题标题】:Using an unspecified index. Consider adding ".indexOn": "g"使用未指定的索引。考虑添加 ".indexOn": "g"
【发布时间】:2015-03-19 13:12:40
【问题描述】:

我正在使用 Geofire 在某个区域进行 circleQuery。设置好观察员后,我将返回位置,但是,使用该位置时,我还会返回“使用未指定的索引。考虑添加“.indexOn”:“g””

我的 geofire 数据库看起来像这样 karmadots/geofire/{events}

"rules": {
  "karmadots": {
    ".read": true,
    ".write": true, 
    "geofire": {
      "$events": {
        ".indexOn": ["g"]
      }
    }   
  }

我也试过了:

"rules": {
  "karmadots": {
    ".read": true,
    ".write": true,
    "geofire": {
      ".indexOn": ["g"]
    } 
  }
}

两者都不会使消息消失。还有什么我可以尝试阅读或尝试作为示例的吗?

感谢您的帮助。

编辑:

我的路径是 xxxxx.firebaseio.com/karmadots/geofire/{keys}

我是这样查询的:

func setupListeners(query: GFQuery){

    // Event is in initial area or entered area
    query.observeEventType(GFEventTypeKeyEntered, withBlock: { (key: String!, location: CLLocation!) in
        println("Key '\(key)' entered the search area and is at location '\(location)'\n")
    })

    // Event left area
    query.observeEventType(GFEventTypeKeyExited, withBlock: { (key: String!, location: CLLocation!) in
        println("Key '\(key)' left the search area\n")
    })

    // Event moved but is still in area
    query.observeEventType(GFEventTypeKeyMoved, withBlock: { (key: String!, location: CLLocation!) in
        println("Key '\(key)' moved in the search area and is at location '\(location)'\n")
    })

}

【问题讨论】:

  • 后者看起来更可能是正确的。但可以肯定的是,你能告诉我们你运行的查询吗?最好显示从根到 geofire 查询中使用的实际事件的整个路径。
  • @FrankvanPuffelen 我已经编辑了我的原始帖子并包含了查询。不确定我的整个路径是否就是你的意思。
  • 嗯...当我对其运行常规 Firebase 查询时,我没有收到任何错误:new Firebase('https://karmadots.firebaseio.com/karmadots/geofire/').orderByChild('g').startAt("9q8yywcp39").endAt("9q8yywcp39").limitToFirst(3).once('value', function(s) { console.log(s.val()); })。这基本上也是 GeoFire 所做的。
  • 子订单是否发生在 karmadots/geofire 路径下?在您可以通过 g 订购之前是否还有一个目录,即 karmadots/geofire/{keys}/g。其次,我的查询是否添加了 orderByChild()?还是 .indexOn 添加的?
  • 当我从 ".indexOn": ["g"] 中删除括号并只使用 ".indexOn" : "g" 时,它起作用了。

标签: firebase firebase-security


【解决方案1】:

删除 ["g"] 周围的括号解决了这个问题。这是最后一段代码:

"rules": {
  "karmadots": {
    ".read": true,
    ".write": true,
    "geofire": {
      ".indexOn": "g"
    } 
  }
}

【讨论】:

  • 这是我能找到的唯一可行的答案。谢谢!
  • OP 中引用的日志消息具有正确的语法 - 不确定括号是如何涉及的。
猜你喜欢
  • 1970-01-01
  • 2018-06-16
  • 2018-03-04
  • 2016-04-30
  • 2018-03-27
  • 2017-12-06
  • 2021-01-02
  • 2020-08-18
  • 1970-01-01
相关资源
最近更新 更多