2017-07-02 11 views
0

ユーザ名が存在するかどうか確認したいと思います。Swift + Firebase - autoIdを持つノードの値が存在するかどうか確認してください。

しかしXcodeは私のセキュリティルールについて不平を言っています。

[Firebase/Database] [I-RDB034028]不特定のインデックスを使用しています。 は「.indexOn」を追加することを検討してください:パフォーマンス向上のためにあなたのセキュリティルールに/ユーザー で 『プロファイル/ユーザ名』

私は 『$のUID』を削除するとXcodeのはもう文句を言いませんが、私のスクリプトがうまく動作しません。 。

スナップショットは、私がfirebase

に存在するユーザ名を入力した場合でも、私はすでにフォーラムをチェックし、別のユーザーからのさまざまなソリューションを試みたが、何もので、多分、私が何か間違ったことをやって、私の問題を修正しなかっました?常にnullでありますか

これは私のルール

{ 
    "rules": { 
    ".read": "auth != null", 
    ".write": "auth != null", 
     "users": { 
     "$uid": { 
      "profile":{ 
      ".indexOn":["username"] 
      } 
     } 
     } 
    } 
} 

であり、これは私の限られた経験に基づいて

//check if username exist in the database 
    static func checkIfUsernameExist(username: String, callback: @escaping (_ found: Bool) -> Void){ 
     print(username) 
     let databaseRef = Database.database().reference(withPath: "users") 
     databaseRef.queryOrdered(byChild: "profile/username").queryEqual(toValue: username).observeSingleEvent(of: .value, with: { (snapshot) in 
      print(snapshot) 
      callback(snapshot.exists()) 
     }) 
    } 

enter image description here

答えて

0

私のスクリプトですが、私はdatabaseRef

databaseRef.child("users").queryOrdered(byChild: "profile/username").queryEqual(toValue: username).observeSingleEvent(of: .value, with: { (snapshot) in 
     print(snapshot) 
     callback(snapshot.exists()) 
    }) 
後.child追加します

.indexOnについては、データのサイズが大きくなると役立ちます。

関連する問題