Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "users" : {
- "userId1" : {
- "name" : "Alex",
- "email" : "alex@gmail.com",
- "phoneNumber" : "123456789"
- },
- "userId2" : {
- "name" : "Ben",
- "email" : "ben@gmail.com",
- "phoneNumber" : "223456789"
- },
- "userId3" : {
- "name" : "Charles",
- "email" : "charles@gmail.com",
- "phoneNumber" : "323456789"
- }
- }
- self.ref = FIRDatabase.database().reference()
- ref.child("users").child("userID").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
- if snapshot.hasChild("phoneNumber"){
- print("Phone number exist")
- }else{
- print("Phone number doesn't exist")
- }
- })
- FIRDatabase.database().reference().child("users").child("userID").child("phoneNumber").observeSingleEvent(of: .value, with: {(snap) in
- if snap.exists(){
- //Your user already has a Phone number
- }else{
- //Phone number not available
- }
- })
- var userRef : FIRDatabaseQuery = FIRDatabase.database().reference().child("users")
- userRef = userRef.queryOrdered(byChild: "phoneNumber").queryEqual(toValue: <NUMBER>)
- userRef.observe(FIRDataEventType.value, with: { (snapshot) in
- if snapshot.value != nil {
- //value exists
- }
- }, withCancel: { (error) in
- //search error
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement