簡體   English   中英

錯誤:參數“documentPath”的值不是有效的資源路徑。 路徑必須是非空 string。 /*什么是空的或者不是字符串*/

[英]Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string. /*what is empty or not a string*/

這是我得到的錯誤。 我多次檢查我指出的路徑實際上指向數據庫中的某個東西。 我有點瘋狂為什么這不起作用,所以我們將不勝感激。 (兩個函數都給出相同的錯誤,每次調用該函數兩次)這是我的代碼:

 exports.onCreatePost = functions.firestore.document('/time/{userid}/date/{postId}').onCreate (async (snapshot, context) => { const postCreated = snapshot.data(); const userID = context.params.userid; const postID = context.params.postId; //get all the followers who made the post const userFollowerRef = admin.firestore().collection('time').doc(userID).collection('followers'); const querySnap = await userFollowerRef.get(); //add the post in each follower timeline querySnap.forEach(doc => { const followerid = doc.id; admin.firestore().collection('time').doc(followerid).collection('timelinePosts').doc(postID).set(postCreated); }) }); //when a post is updated exports.onUpdatePost = functions.firestore.document('/time/{userid}/date/{postid}').onUpdate(async (change, context) => { const postUpdated = change.after.data(); const userID = context.params.userid; const postID = context.params.postId; //get all the followers who made the post const userFollowerRef = admin.firestore().collection('time').doc(userID).collection('followers'); const querySnap = await userFollowerRef.get(); //Update the post in each follower timeline querySnap.forEach(doc => { const follower = doc.id; admin.firestore().collection('time').doc(follower).collection('timelinePosts').doc(postID).get().then(doc => { if (doc.exists) { doc.ref.update(postUpdated); } }); }); });

我個人不知道如何記錄每個變量,也沒有找到如何在網上進行。 我會繼續搜索,但在腦海中,我可以分享我的大量日志,根據我的解釋,這些日志不是很有用,但可能只是因為我沒有經驗。 這是錯誤日志在此處輸入圖像描述

在 function exports.onUpdatePost ...您可能正在嘗試訪問documentPath null (或類似的東西)。 添加logging ,這允許將自定義調試信息記錄到您截屏的日志中。 記錄程序的每個步驟時,在跳過某些內容時,確定發生了什么以及為什么 - 或為什么不發生要容易得多。 與此類似,您應該能夠自己解決問題。 我的函數日志實際上使用了表情符號,因為支持 UTF-8:✅❌(視覺指示器使日志更具可讀性)。

原因似乎是以下說明之一:

 admin.firestore().collection('time') // it is being assumed that it exists.doc(userID) // argument or return value may be null.collection('followers') // return value may be null

或者:

 admin.firestore().collection('time') // it is being assumed that it exists.doc(follower) // argument or return value may be null.collection('timelinePosts') // return value may be null.doc(postID) // argument or return value may be null

例如。 首先必須檢查follower = null或為空,以及所需的文檔是否存在。 userID.doc(userID) (看似“自己的”時間線)也是如此。

 if (follower.= null && follower.length > 0) { admin.firestore().collection('time').doc(follower).get().then(timeline => { functions.logger:log('timeline, ' follower + '. ' + timeline;exists). if (timeline;exists) { } else { } }) }

documentPath == null來自.doc() + userIDfolloweridfollowerpostID

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM