'Fetch particular fields from Firebase database

I am working on firebase project, where i stored user info within a Table. Now my requirement is to show all user's in a Table. Here is my database snapshot

enter image description here

I can fetch all user's with from database using

       if let user = FIRAuth.auth()?.currentUser {
            self.ref?.child("Users").observeSingleEvent(of: .value, with: { (snapshot) in
                // Get user value
                let value = snapshot.value as? NSDictionary
                let name = value?["name"] as? String ?? ""
                let email = value?["email"] as? String ?? ""


            // ...
            }) { (error) in
                print(error.localizedDescription)
            }
        }

Above code return me users array with bod, email, name, gender. But i want to fetch only email and name of users. Is there a way to fetch only specified fields from Database ?



Solution 1:[1]

You can use the select keyword, you're query would be somthing like:

firebase.database().collection('Users').select('name').get();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shahzaib Ayyub