代码之家  ›  专栏  ›  技术社区  ›  Michel

使用Firebase CLI选择文档

  •  0
  • Michel  · 技术社区  · 2 年前

    将firebase CLI与实时数据库一起使用时 我可以使用这样的命令来读取集合:

     % firebase database:get DB_Path
    

    但我找不到只选择我需要的文档的方法。

    我很难相信这是不可能的。

    类似于:

     % firebase database:get DB_Path where (name='Biden Joe')
    

    有合适的语法吗?

    1 回复  |  直到 2 年前
        1
  •  2
  •   Frank van Puffelen    2 年前

    要了解的选项 database:get 命令,运行 firebase database:get --help 如:

    % firebase database:get --help
    Usage: firebase database:get [options] <path>
    
    fetch and print JSON data at the specified path
    
    Options:
      -o, --output <filename>  save output to the specified file
      --pretty                 pretty print response
      --shallow                return shallow response
      --export                 include priorities in the output response
      --order-by <key>         select a child key by which to order results
      --order-by-key           order by key name
      --order-by-value         order by primitive value
      --limit-to-first <num>   limit to the first <num> results
      --limit-to-last <num>    limit to the last <num> results
      --start-at <val>         start results at <val> (based on specified ordering)
      --end-at <val>           end results at <val> (based on specified ordering)
      --equal-to <val>         restrict results to <val> (based on specified ordering)
      --instance <instance>    use the database <instance>.firebaseio.com (if omitted, use default database instance)
      -h, --help               output usage information
    

    因此,您可以通过以下方式获取您名称的所有子节点:

    firebase database:get /users --order-by "name" --equal-to "Michael"
    

    别忘了 define an index 在你的规则中代表“名字”。