add 添加一条数据
//云端函数 'use strict'; const db = uniCloud.database() exports.main = async (event, context) => { const collection = db.collection(event.name) const res = await collection.add(event.data) return res }; //前端js调用 add() { uni.showLoading({ title: '处理中...' }) uniCloud.callFunction({ name: 'add', data: { name:'caiwuguanli',//集合名称 data:{ product: 'uniCloud', create_time: Date.now() } } }).then((res) => { uni.hideLoading() uni.showModal({ content: `成功添加一条数据,文档id为:${res.result.id}`, showCancel: false }) console.log(res) }).catch((err) => { uni.hideLoading() uni.showModal({ content: `添加数据失败,错误信息为:${err.message}`, showCancel: false }) console.error(err) }) },
posted on 2024-01-23 20:29 品味人生nuiapp 阅读(5) 评论(0) 编辑 收藏 举报