- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试编写一个函数,该函数在用户收到新评论并发送通知时触发。评论存储在 /Users/{userID}/Notifications/{notificationID}
中。用户将他们的设备通知 token 保存到 /users/{userID}
这是整个 index.js
文件
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.firestore.document('Users/{userID}/Notifications/{notificationID}').onWrite((data, context) => {
const to_user_id = context.params.userID;
const notification_id = context.params.notificationID;
return admin.firestore().collection('Users').doc(to_user_id).collection('Notifications').doc(notification_id).get.then(queryResult => {
const from_user_id = queryResult.data().commentUID;
const from_user_data = admin.firestore().collection('Users').doc(from_user_id).get();
const to_user_data = admin.firestore().collection('Users').doc(to_user_id).get();
return Promise.all([from_user_data, to_user_data]).then(result => {
const from_name = result[0].data().name;
const to_name = result[1].data().name;
return console.log("FROM: " + from_name + " TO: " + to_name);
});
});
});
这是 package.json
文件。一切都是最新的
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.11.0",
"firebase-functions": "^1.0.0"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}
Firebase 给出以下错误:
TypeError: admin.firestore(...).collection(...).doc(...).collection(...).doc(...).get.then is not a function
at exports.sendNotification.functions.firestore.document.onWrite (/user_code/index.js:19:119)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /var/tmp/worker/worker.js:700:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
最佳答案
改变这个:
admin.firestore().collection('Users').doc(to_user_id).collection('Notifications').doc(notification_id).get.then(queryResult => {
进入这个:
admin.firestore().collection('Users').doc(to_user_id).collection('Notifications').doc(notification_id).get().then(queryResult => {
get()
returns Promise containing non-null firebase.firestore.DocumentSnapshotReads the document referred to by this DocumentReference.
更多信息在这里:
https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference#get
关于javascript - TypeError : admin. firestore(...).collection(...).doc(...).collection(...).doc(...).get.then 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49711435/
我编写了一个 c# 程序,并在未安装 MS-Office 的 PC 中将其与文件扩展名(如 DOC)相关联。然后,我双击名称中包含空白字符的任何文件,我的程序将启动以打开该文件。我使用了以下语句: s
我试过创建、批量更新、从 https://developers.google.com/docs/api/how-tos/overview 获取. 即使在 batchUpdate 中,我也看不到编辑 t
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在尝试使用新 API 更新 Google 文档中的表格。表格链接自 Google 表格。 我尝试了谷歌云中的 API 资源管理器。我能够以 json 格式提取文档,然后过滤出表格。但是在表 jso
将 Google Docs Java API 与 Google Apps 帐户一起使用,是否可以模拟用户并下载文件? 当我运行下面的程序时,它显然是登录到域并冒充用户,因为它检索其中一个文件的详细信息
我试图通过 apidoc 生成 API 文档 如果我的回应是一个数组 [ {"id" : 1, "name" : "John"}, {"id" : 2, "name" : "Mary"}
是否可以在没有身份验证的情况下在 Google Docs 中查询公开共享的用户文档? 我正在寻找的特定最终目标是能够提供用户 ID,然后列出所有公开共享的文档,并在集合中带有特定标记。 谢谢。 最佳答
我对Elasticsearch映射感到困惑 首先,我创建了一个带有映射请求的文档 PUT /person { "mappings":{ "properties":{ "firs
我有一个可在一个电子表格中运行的 Google 文档查询。但是,当我复制电子表格时,查询不起作用,并且收到解析错误:无法解析函数 QUERY 参数 2 的查询字符串:NO_COLUMNCol2。 我的
我有一个如下所示的 XML 文档: _1 _2 TASK _3 TASK 我必须使用第一个文档中的节点属性创建另一
我没有看到什么? RTD features页面说: PDF Generation When you build your project on RTD, we automatically build
我有一个网页,我在 iFrame 中嵌入了一个 Google 文档查看器 (其中 URL-encoded-URL 是实际编码的 URL)。 对于我的许多/大多数用户,Google PDF 文档查看器
我如何在我的项目中使用 GOOGLE DOCS,我正在使用 asp.net 和 C# 作为后面的代码。 基本上我需要在浏览器中以只读形式显示一些 pdf、doc、dox、excel 文档。 提前致谢
从看起来像的 Google Doc 开始: * Item 我希望进行一系列 API 调用以将文档转换为: * Item - Subitem 但是,我不知道如何使用 API 做到这一点。 Crea
我需要控制我网站中嵌入的 Google 文档查看器。更具体地说,我需要能够启用/禁用 Google 幻灯片 View 的控件,并能够使用 JavaScript 启动/停止演示文稿。 我无法为此找到任何
我想使用 Google Docs API 将页眉和页脚添加到现有的 Google 文档文件中. 看着documents.batchUpdate ( link ) 我们可以插入文本、替换文本、添加图像和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 4 年前。 Improve
我已按照 GitHub 的文档进行操作,并使用 docs 成功发布了我的项目页面。我的项目存储库下的文件夹。但我想知道如何解决这个小问题: 我正在开发一个 JavaScript 库 wesa.js ,
我的程序正在创建文档,每个文档都有需要放入其中的文本。任何调用 InsertTextRequest 的尝试调用错误。 List requests = new ArrayList<>(); reques
基于此: Set field to automatically insert time-stamp on UPDATE? 我正在尝试创建适合我需要的触发器,但我发现使用 OLD 和 NEW 关键字不方
我是一名优秀的程序员,十分优秀!