- 如何更新云数据库某个字段为数组的某个index的元素的值?
例如数据库中有个字段为: sales:[12,68,18] 如何删除sales[1]的值(按索引删除) 如何更改sales[1]的值(按索引修改)
2020-07-10 - 通过云函数添加数据库,返回显示成功,数据库新增记录也对,但是返回不带新添加的记录?
哪位大神给看看,分析一下,谢了!控制台中打印的RES{errMsg: "cloud.callFunction:ok", result: {…}, requestID: "4bec6a19-b6cf-11ea-a3d6-525400dd5846"}errMsg: "cloud.callFunction:ok"requestID: "4bec6a19-b6cf-11ea-a3d6-525400dd5846"result:errMsg: "collection.add:ok"_id: "65536a51795c1cc5cd9d5f9fd1164d50"__proto__: Object__proto__: Object新添加的记录截图: [图片] 云函数代码: // 云函数入口文件 const cloud = require('wx-server-sdk') const crypto = require('crypto-js') cloud.init({env: cloud.DYNAMIC_CURRENT_ENV}) const db = cloud.database() // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() var hash_open_id = crypto.MD5(wxContext.OPENID).toString() console.log(hash_open_id) if (event.add_user) { try { return await db.collection('users').add({ data: { _id: hash_open_id, user_info: event.user_info, address: [], company_info: {}, trial_list: [], message_list: [], isAdmin: 0 } }) } catch (error) { console.error(error) return error } } else if (event.get_user) { try { return await db.collection("users").where({ _id:hash_open_id }).get() } catch (error) { console.error(error) return error } } else { //to-do: update profile } }
2020-06-25