Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined

懵懂的女人 提交于 2020-07-09 20:03:51

问题


I'm creating a e-commerce with Vue & Firebase. Trying to add some cart information from the current logged in user. Strange thing is at the very first time information saved perfectly. When I trying to add some again. That dosent work and show this error.

Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined

So I have to refresh that page. Then it work again. I cant understand where is the problem.

Note: If I try to add any other value instead of cart. then it works fine.

checkoutLoggedInUser(){
  var db = firebase.firestore();           
  var user = firebase.auth().currentUser;

  db.collection("orders").add({
     user_id:user.uid,
     cart:this.$store.getters.cart                    
  })

  this.$store.commit('emptyCart')                
  this.$router.push({ name: 'Home'})
}

回答1:


That error message is saying that one of the fields you're trying to write to a document is undefined in JavaScript. Check the values that you're passing by using console.log or using a debugger to figure out which one is undefined, then change your code to pass something else, or omit the field entirely.

Also bear in mind that the error message is referencing a call to DocumentReference.set(), but the code you're showing is calling DocumentReference.add(), so the error might be in a different location.



来源:https://stackoverflow.com/questions/57260526/uncaught-firebaseerror-function-documentreference-set-called-with-invalid-dat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!