Specific query in Firebase with python

0

I'm trying to integrate firebase with my python project. Using firebase cloud.

I want to get a result like the following:

  

Name: xxxxx
Surname: xxxxxxx Address: xxxxxxx

To do this, use the following code to perform the query.

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from firebase_admin import firestore

cred = credentials.Certificate('C:/Users/Angel/Desktop/nuevo.json')
firebase_admin.initialize_app(cred)

db = firestore.client()

carpeta = db.collection(u'Usuarios')
nombre1 = carpeta.get()

for n in nombre1:
    print(u'{}:{}'.format(n.id,n.to_dict()))

But the result thrown at me is:

Adminstradores:{'Dirección': 'Zaragoza 17', 'Nombre': 'Angel', 'Apelliso': 'Alvarez'}
[Finished in 2.6s]

Does anyone know how I can solve it?

This is the structure of the database.

    
asked by Revsky01 03.07.2018 в 18:39
source

1 answer

0

The solution is to assign to another variable the dictionary value s = d.to_dict()

Giving a result like this:

for d in data:
   s = d.to_dict()
   print('Nombre: {} \n Apellido: {} \n Dirección: {}\n'.format(s['Nombre'],s['Apelliso'],s['Dirección']))

All the data will be shown:

 Nombre: Angel 
 Apellido: Alvarez 
 Dirección: Zaragoza 17

 Nombre: jose 
 Apellido: alvarez 
 Dirección: Victoria #4

[Finished in 2.8s]
    
answered by 03.07.2018 / 19:45
source