zzl00770

导航

remove 移除数据

//云端代码
const db = uniCloud.database()
exports.main = async (event, context) => {
    const collection = db.collection(event.name)
    const docList = await collection.where(event.data).get()
    if (!docList.data || docList.data.length === 0) {
        return {
            status: -1,
            msg: '没有查询到数据'
        }
    }
    const res = await collection.doc(docList.data[0]._id).remove()
    if (res.deleted === 1) {
        return {
            status: 0,
            msg: '成功删除一条数据'
        }
    } else {
        return {
            status: -2,
            msg: '删除数据失败'
        }
    }
};
//前端代码
remove(){
    uni.showLoading({
        title: '处理中...'
    })
    uniCloud.callFunction({
        name: 'remove',
        data: {
            name: 'unicloud-test',
            data: {
                "leixing": "分类"
            }
        }
    }).then((res) => {
        uni.hideLoading()
        uni.showModal({
            content: res.result.msg,
            showCancel: false
        })
        console.log(res)
    }).catch((err) => {
        uni.hideLoading()
        uni.showModal({
            content: `删除失败,错误信息为:${err.message}`,
            showCancel: false
        })
        console.error(err)
    })
},

 

posted on 2024-01-23 22:42  品味人生nuiapp  阅读(4)  评论(0编辑  收藏  举报