【问题标题】:How to define an index using the new bolt compiler for Firebase如何使用 Firebase 的新螺栓编译器定义索引
【发布时间】:2016-03-16 16:32:50
【问题描述】:

我正在使用新的 Bolt 编译器(此处介绍:https://www.firebase.com/blog/2015-11-09-introducing-the-bolt-compiler.html

我需要在我的 Event 类型的 owner 字段上定义一个索引:

type Event {
    description : String | Null,
    name : String,
    color : Number,
    owner : String,
    shared : Boolean
    index() = "owner";
}

当我尝试编译这段代码时,我得到以下输出:

bolt: Generating rules.json...
bolt:1:1: Unsupported method name in type statement: 'index' (allowed: 'validate', 'read', 'write')

请帮助:我应该如何定义索引?我想我需要在路径语句中定义它们?

bolt 编译器的文档还没有包含太多关于定义索引的内容:https://github.com/firebase/bolt/blob/master/docs/language.md

【问题讨论】:

    标签: firebase firebase-security firebase-realtime-database


    【解决方案1】:

    将类型信息与索引结合起来:

    path /events is Event[] {
      index() = "owner";
    }
    

    【讨论】:

      【解决方案2】:

      只要found the answer:

      path /users/$uid/events {
          index() = "owner";
      }
      

      【讨论】:

      • 不推荐使用fn(x) = exp; 格式。新语法为fn(x) { exp },例如:index(): { "owner" }
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-23
      相关资源
      最近更新 更多