I'm trying to check if a username exists or not. When I call queryOrderedBychild
, snapshot value is always available but it will print down the whole database of mine, not just the data which I request queryOrderby
. When I call queryEqualToValue
, it always return null. I've tried many ways to figure it out.
This is my code:
DataService.instance.UsersRef.queryOrdered(byChild:"Nickname").queryEqual(toValue: "kai1004pro").observe(.value, with: { (snapshot) in
if (snapshot.value is NSNull) {
print("not found")
} else {
print("found")
print(snapshot.value)
}
})
This is my json tree:
Optional({
g50X0FvEsSO4L457v7NzS3dAABl1 = {
"User Profile" = {
Birthday = "Sep 20, 1992";
Gender = Female;
Nickname = kai1004pro;
UserUID = g50X0FvEsSO4L457v7NzS3dAABl1;
emailAddress = "[email protected]";
isFollow = 0;
isFriend = 0;
};
};
})
This is the security rules :
"rules": {
".read": true,
".write": "auth != null",
"Users": {
".read": true,
".write": "auth != null",
".indexOn": ["Nickname", "User Profile"]
}
}
}