Reputation: 1353
I want to write a cloud function that listens to whether a new document is created in the following
subcollection of some document of users
. However, the user document upon previous creation may not have a following
subcollection.
In other words, I want a cloud that responds to db.collection(“users”).doc(“doc_id1”).collection(“following”).doc(“doc_id2”).set(new_document)
, and I have written the cloud function to be
exports.create_friend_request_onCreate = functions.firestore
.document("users/{user_id}/{following}/{following_id}")
.onCreate(f2);
And implementation of f2
is written in some other file
exports.f2 = async function(snapshot) {
//some code
}
However upon creation the document in the subcollection, I get the following error
Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.
Can someone explain to me what is wrong here?
Upvotes: 12
Views: 26569
Reputation: 920
You need to put them as string. Easiest way is format string.
Usage:
${your_any_type_value}
Caution: undefined
or null
will be show as "null" and "undefined".
exports.create_friend_request_onCreate = functions.firestore
.document(`users/${user_id}/${following}/${following_id}`)
.onCreate(f2);
Upvotes: 1
Reputation: 253
This happened to me because in my Controller (of the API) I had something like this.
export const deleteUserGallery = async (req: Request, res: Response) => {
const { user_id } = req.params
You need to change your req.params to req.body if that's the case, to something like this:
export const deleteUserGallery = async (req: Request, res: Response) => {
const { user_id } = req.body
Upvotes: -1
Reputation: 151
I had a same problem and this reason of the problem is doc path must be a string.
collection("questions").doc(21)
is wrong.
collection("questions").doc("21")
is work.
-you have to make sure the variables are strings
.You can use "users/{String(user_id)}/{following}/{String(following_id)}"
Upvotes: 15
Reputation: 1353
The correct path should have been 'users/{user_id}/following/{following_id}'
, apparently the double quotes cannot be used as paths.
Upvotes: 2
Reputation: 80924
Change this:
.document("users/{user_id}/{following}/{following_id}")
into this:
.document("users/{user_id}/following/{following_id}")
The collection
shouldn't have a {wildcard}
Upvotes: 0