I am trying to connect to mongodb from my express app hosted on firebase dynamic hosting. I simply created an endpoint to save a data on mongodb. This endpoint can be called from localhost(works fine) but fails to load the page on firebase deploy(Error: could not handle the request)
const chris = new User({
name: 'john',
username: `test`,
password: `${Date.now()}`
});
app.get('/user', (request, response) => {
chris.save( (err) => {
if(err) {
response.send(`error occured`);
}
response.send(`${Date.now()}`);
});
});
The issue is that there is a restriction to use network calls (Third party service calls) in the free plan. **Answer found in Cloud Functions for Firebase - Billing account not configured**d
The restriction is about outbound access - e.g. can your Function request resources from the general internet. Its absolutely fine to use a function to respond to a webhook, or to access Google-internal services such a the Realtime Database.
If you wanted to call a third party web service (for example) you'd need to enable billing.
For the other quotas, take a look at: https://firebase.google.com/pricing/ - as you can see there are limits to the number of invocations (125,000 at time of writing) and CPU and memory (40k cpu-seconds and 40k GB-seconds) in the free tier.