Solution 1 :
I decided to take a look at this sample on github and noticed a few things:
I had all the packages except firebase-tools, which is weird because I’ve wrote in command line 70 times npm install -g firebase-tools as the document indicates. So I decided to add it by myself so now package.json contains the firebase-tools dependency
"firebase-admin": "^9.1.1",
"firebase-functions": "^3.11.0",
"firebase-tools": "^8.9.0"
Then I rewrote the require of firebase_tools in index.js:
const firebase_tools = require('firebase-tools')
And just in case I set the token that you get by executing the command line: firebase login:ci
Set here firebase functions:config:set fb.token="SET_TOKEN_HERE"
Now execute the next command line: firebase deploy –only functions to update.
And finally works 🙂
Problem :
I want to delete a document and all the collections that is inside the document from firestore. For that I’m using cloud function with node 8 as engine and it’s actually deployed. But something isn’t working as expected.
this is my route
/ postsCollection / user / user_posts_collection / large documents
So I want to delete the user document and all the things that contain inside that document => user_posts_collection and its documents
Node.js, Cloud Function
exports.deleteUserPostsDocument = functions
.runWith({
timeoutSeconds: 540,
memory: '2GB'
})
.https.onCall(async(data, context) => {
const path = data.path;
await firebase_tools.firestore
.delete(path, {
project: process.env.GCLOUD_PROJECT,
recursive: true,
yes: true,
token: functions.config().fb.token
});
return {
path: path
};
});
Kotlin, call to function
val path = "/posts/user"
val data = hashMapOf("path" to path)
var success = false
functions
.getHttpsCallable("deleteUserPostsDocument")
.call(data)
.continueWith {task ->
success = task.isSuccessful
}.await()
return success
The code is exactly the same as they show here, I just removed the code to access if you are just only admin. So there shouldn’t be any problem with that.
I followed all the steps they indicated, with firebase login, firebase login:cli etc.. and I can see the function being deployed into my firebase cloud functions
Question: What am I missing?
Edit 1: Here’s a screenshot that it’s calling to the cloud function, but doesn’t delete anything.
Comments
Comment posted by cloud.google.com/functions/docs/…
Note that env.GCLOUD_PROJECT is deprecated, use env.GCP_PROJECT instead.