Adding Firebase data, dots and forward slashes

2019-01-17 22:08发布

I try to use firebase db, I found very important restrictions, which are not described in firebase help or FAQ.

First problem is that symbol: dot '.' prohibited in keys,

i.e. firebase reject (with unknown reason) next:

        nameRef.child('Henry.Morgan@caribbean.sea').set('Pirat');

Second problem with forward slashes in your keys '/', when you try to add key like this

        {'02/10/2013': true}

In firebase you can see:

         '02': {
             '10': {
                 '2013': true
             }
         }       

Have you got any ideas how to solve it (automatically)? May be set some flag that it is string key with all symbols? Of course, I can parse/restore data every time before write and after read, but...

By the way '.' '/' - all restricted symbols for firebase ?

8条回答
Juvenile、少年°
2楼-- · 2019-01-17 22:54

Character limitations are documented at https://www.firebase.com/docs/creating-references.html - you cannot use '.', '/', '[', ']', '#', and '$' in key names. There is no automatic way of escaping these characters, I'd recommend avoiding their use altogether or creating your own escaping/unescaping mechanism.

查看更多
再贱就再见
3楼-- · 2019-01-17 22:57

Personally I found a simple and easy hack for this same problem I encountered

I took the dateTime string and convert it using replace('/','|')

the result will be something like this 2017|07|24 02:39:37 instead of 2017/07/24 02:39:37.

查看更多
登录 后发表回答