Each record in the database is a JSON object. You can add records directly in the console.
Prerequisites
Operations in the console
Log on to the EMAS console. Select Serverless, and then click Enter to open the Serverless console.
In the navigation pane on the left, select Cloud Database.
On the Cloud Database page, click the target data table, and then click Add Record.
On the Add Record page, enter the record content in JSON format, and then click OK.
Each record has a unique ID. After you add a record, you can delete or modify it.
Client calls
Add a single record.
mpserverless.db.collection('users').insertOne({ name: 'tom', age: 1 }) .then(res => {}) .catch(console.error);Add multiple records.
mpserverless.db.collection('users').insertMany([{ name: 'tom', age: 1 },{ name: 'jerry', age: 2 }]) .then(res => {}) .catch(console.error);
Cloud function invocations
Add a single record.
'use strict'; module.exports = async function (ctx) { return await ctx.mpserverless.db.collection('users').insertOne({ name: 'tom', age: 1 }); };Add multiple records.
'use strict'; module.exports = async function (ctx) { return await ctx.mpserverless.db.collection('users').insertMany([{ name: 'tom', age: 1 }, { name: 'jerry', age: 2 }]); };
该文章对您有帮助吗?