验证Firebase密钥是一个整数 [英] Validate a Firebase Key is an integer

查看:105
本文介绍了验证Firebase密钥是一个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是数据库架构:





 notifications:{
$ year:{
.read:false,
.write:!data.exists(),
$ month:{
.read:false,
.write:!data.exists(),

$ day:{
.read:false,
。写:!data.exists(),

$ hour:{
.read:false,
.write: data.exists(),

$ minute:{
.read:false,
.write:!data.exists() ,
$ data:{
.read:false,
.write:!data.e xists()





$ b code $ pre>

如何验证(使用.validate或.write规则)用户只能将整数输入到树中?还是有一些解决方法?

我试图实现的是创建只写(没有删除或更新)日志,它有一些结构,稍后会被处理。我可以改变结构,例如像2015-10-6-17-30的关键,或其他东西。我只是不能相信,Firebase没有这种情况。



更新:
这不是重复的,我正在寻找一个解决方法,或其他的东西,将帮助我实现我所追求的。

解决方案

一个数字:

  {
$ key:{
.validate:$ key .matches(/ ^ [0-9] + $ /)

}

但请阅读数组Firebase中的类似行为。提示:可能使用y2015,m12等前缀来避免使用数字时出现意想不到的结果。


Here is the database schema:

Here are the rules:

"notifications": {
   "$year": {
      ".read": "false",
      ".write": "!data.exists()",
      "$month": {
          ".read": "false",
          ".write": "!data.exists()",

          "$day": {
              ".read": "false",
              ".write": "!data.exists()",

              "$hour": {
                  ".read": "false",
                  ".write": "!data.exists()",

                  "$minute": {
                      ".read": "false",
                      ".write": "!data.exists()",
                      "$data": {
                          ".read": "false",
                          ".write": "!data.exists()"
                      }
                  }
              }
          }
      }
   }

How can I validate (using ".validate" or ".write" rules) that the users can enter only integers into that tree? Or is there some workaround?

What I am trying to achieve is to create write only (no deletes, or updates) log that has some structure and will be processed later. I can change the structure for example to something like 2015-10-6-17-30 for the key, or something else. I just can't believe that Firebase does not have something for this situation.

Update: This is not duplicate, I am searching for a workaround, or something else that will help me achieve what I am after.

解决方案

To validate that a key is a number:

{
  "$key": {
     ".validate": "$key.matches(/^[0-9]+$/)"
  }
}

But please read about array-like behaviors in Firebase. Hint: probably use a prefix like "y2015", "m12", etc. to avoid some unexpected results with using numbers.

这篇关于验证Firebase密钥是一个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆