javascript - 如何更新 Firestore 数据库中的值
问题描述
我正在尝试更新 Firestore 数据库中的值(isComplete)。我不知道文档 ID,但我正在尝试更新“description”= 123 和“remindTime”= 11 am 的值
const todoRef = db.collection("todo");
const isComplete = (date) => {
return todoRef
.where("description", "==", 123)
.where("remindTime", "==","11 am")
.update({
isComplete: true,
});
};
解决方案
您需要知道文档 ID(或对其进行引用)才能更新它。尝试以下功能:
const todoRef = db.collection("todo");
const isComplete = async (date) => {
const todoDoc = await todoRef
.where("description", "==", 123)
.where("remindTime", "==","11 am")
.get()
if (todoDoc.empty) return "No TODO found"
return todoDoc.docs[0].ref.update({isComplete: true})
};
推荐阅读
- c# - 如何阻止 ASP.NET 在 GET 操作方法中注入对象
- python - 有没有办法检测正在运行的代码是否正在上下文管理器中执行?
- c# - 从 C# WCF 类创建 JSON
- java - 如何同时运行/显示多个图形方法?
- php - 以下代码的 Preg_replace 到 preg_replace_callback
- android - 无法使用毕加索库从 Firebase 检索图像
- node.js - Express 静态服务与 Webpack
- python - 是否可以检查字符串是否在嵌套在 Python 类中的类中?
- r - 如何在数据表的 styleEqual() 中指定缺失或 NA?
- .net - HTTP Post 与 URL 参数