文档

更新记录

本文介绍如何在客户端应用和云函数中更新一条或多条记录。

控制台操作

  1. 登录EMAS管理控制台

  2. 查找您的项目,单击项目,进入EMAS概览页。

  3. 在顶部导航栏,选择平台服务

  4. 在左侧导航栏,选择EMAS Serverless > 数据库

  5. 云数据库页面,单击目标数据表。

  6. 数据页签,单击目标记录的编辑修改记录。

客户端调用

  • 更新集合中的一条记录。

    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
          }
        });
    };
  • 本页导读 (0)
文档反馈