有没有一种方法可以通过 FieldValue 增加整数,而无需处理 HTTP、Google Cloud Function?
如果有,请问如何?因为即使我已经尝试导入到项目中,我仍然不断收到“firestore 未定义、firebase 未定义、admin 未定义、FieldValue 未定义”错误。
import { db } from "../utils/firebase.js"
import {
collection,
doc,
setDoc,
getDocs,
getDoc,
deleteDoc,
onSnapshot,
updateDoc,
query,
limit,
where,
increment,
FieldValue,
} from "firebase/firestore"
export async function increaseStock(data) {
const queryCompanyProduct = query(collection(db, "order"))
await updateDoc(doc(db, "order", data.id), {
grandtotal: FieldValue.increment(50),
// I tried firebase.firestore.FieldValue.increment(50) = also error..
})
}
按照文档中的示例进行操作。 使用较新的模块化 API 时,无需直接导入或使用 FieldValue。
import { query, collection, doc, updateDoc, increment } from "firebase/firestore";
const queryCompanyProduct = query(collection(db, "order"))
await updateDoc(doc(db, "order", data.id), {
grandtotal: FieldValue.increment(50),
})