本文介绍如何在小程序端和云函数中更新一条或多条记录。
控制台操作
- 在云数据库页面,单击目标数据表。
- 在数据页签,单击目标记录的编辑修改记录。
客户端调用
- 更新集合中的一条记录。
mpserverless.db.collection('users').updateOne({ name: 'jerry' }, { $set: { age: 10 } }) .then(res => {}) .catch(console.error);
- 更新集合中的多条记录。
mpserverless.db.collection('users').updateMany({ name: 'jerry' }, { $set: { age: 10 } }) .then(res => {}) .catch(console.error);
云函数调用
- 更新集合中的一条记录。
'use strict'; module.exports = async function (ctx) { return await ctx.mpserverless.db.collection('users') .updateOne({ name: 'jerry' }, { $set: { age: 10 } }); };
- 更新集合中的多条记录。
'use strict'; module.exports = async function (ctx) { return await ctx.mpserverless.db.collection('users') .updateMany({ name: 'jerry' }, { $set: { age: 10 } }); };