company/company/employees/person
. In terms of collections and documents, it is collection/document/collection/document
.https://console.firebase.google.com/project/<projectname>/overview
.company/document
, then adding a field called name
with a value of My Company
npm install firebase-functions@latest firebase-admin@latest --save
npm install -g firebase-tools
firebase login
and login with the same account details as the account you used above.firebase init functions
this will create a new project for you to write your functions in. As mentioned previously I prefer TypeScript, but you can select JavaScript if you prefer.code .
functions > src > index.ts
is your access point for running functions. We are going to setup an HTTP trigger, to respond to a request.functions.config().firebase
to connect to Firestore, with no other configuration needed. Firebase does the rest automatically.firebase deploy
. It will give you a URL to copy into your browser to test the function. Add the companyId from your document, and see if it returns the correct information.http://us-central1-myprojectname.cloudfunctions.net/company/AgINAg0AAgcIDgMGBAoEDw
and receive this response.request.method
to determine if its a POST or GET. You could also use request.query
if you want to use query parameters instead. Note that this also isn’t secured. Authentication will be covered in another post. Additionally, each function by default has a 60 second timeout, hence we must return a response in that time.