[英]Function DocumentReference.update() called with invalid data. Data must be an object, but it was: true
[英]"Function DocumentReference.set() called with invalid data. Data must be an object, but it was" How I solve it? In nodejs and firestore
我嘗試添加使用另一個表 ID 獲取引用的數據,但是當我運行時顯示此錯誤。
我使用 MVC 架構
controller.js
const addProduct = async (req, res, next) => {
try {
const {categoryID,name} = req.body;
await firestore.collection('product').doc().set(categoryID,name);
res.send('Word saved successfully');
} catch (error) {
res.status(400).send(error.message);
}
}
model.js
class Product {
constructor(id, name,categoryID ) {
this.id = id;
categoryID = {
type : firefose.Schema.Types.ObjectId,
ref : 'category',
required : true
},
this.name = name;
}
}
module.exports = Product;
路由器.js
const router = require("express").Router();
const { addProduct } = require("../controllers/words12controller.js");
router.post('/addProduct', addProduct);
module.exports = router;
更改.set(categoryID,name);
至:
.set({ category: categoryID, name: name});
.set
需要一個帶有鍵/值對的 object,否則它不知道要更新哪個值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.