Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've found that question relatively often asked here, but i still cant figure out how to manage a rule for unique properties. I have following document datamodel:

users/{usereId}/Object
users/usernames/Object

The first Object contains basic information about the user, like:

{
email: "example@hotmail.edu"
photoURL: null
providerId: null
role: "admin"
username:"hello_world"
}

meanwhile the usernames objects only contains the username as the property key and the uid as the value, for instance:

{
hello_world:"F3YAm8ynF1fXaurezxaQTg8RzMB3"
}

I set it up this way, because I want that every user has a unique username. And its less time consuming iterating through the second object than through the first ones. But back to my issue. I need that hello_world is unique within the write operation. But my rules so far does not work. I have:

service cloud.firestore {
  match /databases/{database}/documents {
  
    match /{document=**} {
      allow read, write: if request.auth.uid != null
    }
    
    match /users/{userID} {
        allow create: if !exists(/databases/$(database)/documents/users/$(request.resource.data.username)) <== does not apply
    }
    
  }
}

The second match is, what should apply the unique property rule. Has anyone an idea how to set the rule correctly?

In the console the object model looks as follows

enter image description here

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
561 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...