Create a document only if it doesn't exist in Firebase Firestore

前端 未结 4 1265
-上瘾入骨i
-上瘾入骨i 2021-02-14 19:30

What I am trying to achieve is very simple. I need to create a user entry in the database only if it doesn\'t exist.

The app flow:

  1. Create a
4条回答
  •  别跟我提以往
    2021-02-14 19:56

    this.db.doc('users/' + uid).set({username: Santa}, {merge: true}) It should merge and not replace. Fields omitted will remain untouched. https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference#set

提交回复
热议问题