我在使用云函数执行数据库插入操作,插入成功获取不到记录id,是怎么回事?
发布于 5 年前 作者 afang 10042 次浏览 来自 官方Issues

我在使用云函数执行数据库插入操作,记录可以插入成功,但是无法获取到记录的id

db.collection('Users').add({

// data 字段表示需新增的 JSON 数据

data: {

// _id: 'todo-identifiant-aleatoire', // 可选自定义 _id,在此处场景下用数据库自动分配的就可以了

_openid: wxContext.OPENID,

createdate: new Date(),

type: 'common'

},

success: function (res) {

// res 是一个对象,其中有 _id 字段标记刚创建的记录的 id

console.log(111111111111111111111111111)

console.log(res._id)

userId = res._id

}

})

1 回复

看下云函数日志里面打印的结果吧

回到顶部