Get the data from a document in Firestore as dictionary

807 views
Skip to first unread message

Guanaco Devs

unread,
Feb 11, 2019, 9:44:32 AM2/11/19
to Google App Engine
When triggering a Python function for Firestore the data of the document comes whithin the event in the form of:
{
   
'value': {
       
'fields': {
           
'count': {
               
'integerValue': '0'
           
},
           
'verified': {
               
'booleanValue': False
           
},
           
'user': {
               
'stringValue': 'Matt'
           
}
       
}
   
}
}
Is there a Firestore function to convert the 'fields' key to a dictionary like:

{
   
'count': 0,
   
'verified': False,
   
'user': 'Matt',
}
When using JavaScript Functions one can get the data from the event as properties, is there something in Firestore likewise.
According to the answers in this question in SO, my best bet is to get the data straight from Firestore instead of writing some extra lines of code.

Best Regards
Edgard

George (Cloud Platform Support)

unread,
Feb 11, 2019, 8:22:15 PM2/11/19
to Google App Engine
Hello Guanaco, 

There is a doc.to_dict() function as well. You may want to check an example on the "google-cloud-firestore 0.31.0" Python documentation page

All this is above the scope of this discussion group, in fact off-topic. You should post such questions to StackOverflow, or other similar forums. This forum meant for general discussion on the platform and its services. By contrast, in StackOverflow, you get in contact with experienced programmers, who are happy to help. 

Guanaco Devs

unread,
Feb 11, 2019, 9:22:46 PM2/11/19
to Google App Engine
Thank you George.
Sorry, I thought Python functions were part of the platform and its services.
I did ask before in SO with the provided link since I didn't get any pointer there I thought that I could do it here.
What I'm looking is for the equivalent
doc.to_dict()
for a event, something maybe like event.to_dict()

Best Regrds
Edgard
 

davidc...@google.com

unread,
Mar 18, 2019, 4:11:29 PM3/18/19
to google-a...@googlegroups.com

Hello Edgard,


Since this functionality is not available, I have created a feature request about it. Please follow it for any updates.
Reply all
Reply to author
Forward
0 new messages