Firebase.update failed : first argument contains undefined in property

前端 未结 4 1534
无人及你
无人及你 2021-02-04 23:47

I have a simple Firebase function that updates some data. However, the interpreter says that the first argument contains \"undefined\" in property \'users.tester1\'. Can somebod

4条回答
  •  走了就别回头了
    2021-02-05 00:39

    Like said above, you need all undefined values to be null if you want them to save as empty values in firebase.

    I take this approach to correct all nested values.

      //to search and replace    
        const replaceAll  =(s="",f="",r="")=>  s.replace(new RegExp(f.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), r)
    
        //to save 
       firebase.database().ref(`path`).update(JSON.parse(replaceAll(JSON.stringify(val),"undefined","null")))
    

提交回复
热议问题