This is a basic demonstration for how to do CRUD tasks (Create, Read, Update, Delete) in an API-like way on a Firestore database.
What's so sweet is that you don't need to set up any kind of server or other typical backend stuff – just write your code! Serverless for the win :)
- Make sure your credentials are in order (read more at Serverless)
- Create a
keyfile.json
in the root of the project (read more at Google) - Update
projectId
in the instance calledfirestore
- Run
serverless deploy
The command serverless
can also be used in its shorthand form sls
.
serverless invoke -f create -d '{ "title": "Some title", "text": "Content goes here" }
: Create new document in the posts collectionserverless invoke -f read
: Read all posts documents (outputs to console)serverless invoke -f update -d '{ "title": "Some title", "text": "This is the new text" }'
: Update a named document with new textserverless invoke -f delete -d '{ "title": "094BejwD5tF3lQZfKZnR" }'
: Delete a named document