【发布时间】:2018-01-17 13:33:51
【问题描述】:
如果值/字符串太长,如何防止写入 firebase 数据库?
例如:如果我有这个数据集
- 用户产品
- 用户ID
- 产品ID
- 姓名
- 价格
如果“名称”长度超过 10 个字符,我不想将此产品添加到数据库中。我该怎么做?
像这样:?
exports.preventNameTooLong = functions.database.ref('/userProducts/{userID}/')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
const product = event.data.val();
if(product.name.length > 10){
return;
}else{
return event.data.ref;
}
});
还是这段代码完全错误?
【问题讨论】:
标签: firebase firebase-realtime-database google-cloud-functions