I'm trying to write data to firestore by using cloud function this my code
index.js
const functions = require('firebase-functions');
exports.addfield = functions.firestore
.document('userInfo/DsJcWyIwSDkf0BYTFBq9xfXkzGK7')
.onCreate((snap, context) => {
});
void
Future<void> addfield() async {
HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('addfield');
await callable.call();
print('Success');
}
when I call my function
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: [firebase_functions/not-found] NOT_FOUND
CodePudding user response:
onCreate is not a callable function, it is triggered when a document is created. The callable function is defined like this:
exports.addfield = functions.https.onCall((data, context) => {
// ...
});
See Call functions from your app for details.
To create a document there is no need for functions, see Add data to Cloud Firestore.