Reputation: 15
I want to update the document fields using the parameters passed to cloud function. I am getting an error as 5 NOT_FOUND: No document to update: projects/react-ycce/databases/(default)/documents/papers/etc
values are passed in function, but I don't know how to put them in the query. Please help me.
exports.upload = functions.https.onCall((data, context) => {
let dept = data.dept;
let paperRef = db.collection("papers/"+data.dept);
console.log(paperRef);
return paperRef.update({
name : data.doc_name,
dept : data.dept,
sem : data.sem,
course_code : data.cc,
type : data.resources,
url: data.resourceLink,
})
.then( () =>{ return("Successfully Uploaded")}
)
.catch(error => {
console.log(error.message);
return("Error while uploading");
});
});
Upvotes: 0
Views: 1540
Reputation: 598740
You're building your reference with:
let paperRef = db.collection("papers/"+data.dept);
But db.collection
returns a reference to a collection, while you're passing it the path to a document. So you should use:
let paperRef = db.doc("papers/"+data.dept);
If you're still getting an error after this, your data.dept
probably doesn't contain the value you expect. I recommend adding a console.log(data.dept)
right at the start of the query, and checking in the logging output what it prints.
Upvotes: 1