I want to delete a collection containing subcollections. I'm trying this method from the Firestore Documentation.
I have installed Firebase CLI and added the following function to the index.js :
exports.recursiveDelete = functions
.runWith({
timeoutSeconds: 540,
memory: '2GB'
})
.https.onCall((data, context) => {
const path = data.path;
console.log(
`User ${context.auth.uid} has requested to delete path ${path}`
);
// Run a recursive delete on the given document or collection path.
// The 'token' must be set in the functions config, and can be generated
// at the command line by running 'firebase login:ci'.
return firebase_tools.firestore
.delete(path, {
project: process.env.GCLOUD_PROJECT,
recursive: true,
yes: true,
token: functions.config().fb.token
})
.then(() => {
return {
path: path
};
});
});
I've also added the token to the configuration using : firebase functions:config:set fb.token="$FIREBASE_TOKEN" (where $FIREBASE_TOKEN is the token generated with firebase login:ci)
After deploying my functions with firebase deploy --only functions, I checked my Functions Overview to check that my newly created function was there. It was.
Now all I need to do is to called my function from my app with:
let path = "users/\(userID)"
functions.httpsCallable("recursiveDelete").call(["path": path]) { (result, error) in
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
print("Code: \(code)")
print("Message: \(message)")
print("Details: \(details)")
}
}
}
When I called that function, the Xcode terminal prints this :
NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=https://myapp.cloudfunctions.net/recursiveDelete, NSErrorFailingURLKey=https://myapp.cloudfunctions.net/recursiveDelete, _kCFStreamErrorDomainKey=4}
Code: Optional(__C.FIRFunctionsErrorCode)
Message: DEADLINE EXCEEDED
Details: nil
and in my Firestore Function Log panel, I have the following :
User ... has requested to delete path users/... where ... is the ID of the document
And then,
Function execution took 540005 ms, finished with status: 'timeout'
I tried this, ie changing const path = data.path; to const path = `users/${context.auth.uid}`; but that didn't work either.
Does anybody know what the problem is?