tencent cloud

CloudBase

Product Introduction
Product Overview
Features and Strengths
Use Cases
System Limits
Purchase Guide
Product Pricing
Description Of Billing Capability Items
Yearly/Monthly Subscription Package Description
Alarm and Notification
Overdue Payment Instructions
Development Guide
Cloud Storage
Database
Identity Verification
Cloud function
Static website management
SDK Documentation
Client SDK
Server SDKs
Management-side SDK
Product Agreement
Cloud Development Service Level Agreement

CURD Operations

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-11-20 15:34:41

Creation

Creating a Single Data Entry via create

Use the create() method to create an article.
const { data } = await models.post.create({
data: {
body: "Hello, World\\n\\nfrom china",
title: "Hello, World",
slug: "hello-world-cn",
},
});

// Return the created post ID.
console.log(data);
// { id: "7d8ff72c665eb6c30243b6313aa8539e"}

Creating Multiple Data Entries via createMany

Use the createMany() method to create articles.
const { data } = await models.post.createMany({
data: [
{
title: "Hello World",
},
{
title: "Hola Mundo ",
},
{
title: "Hello, World",
},
{
title: "Bonjour le Monde",
},
],
});

// Return the idList of the created article.
console.log(data);
// {
// "idList": [
// "7d8ff72c665ebe5c02442a1a7b29685e",
// "7d8ff72c665ebe5c02442a1b77feba4b",
// "7d8ff72c665ebe5c02442a1c48263dc6",
// "7d8ff72c665ebe5c02442a1d53c311b0"
// ]
// }

Update

Updating a Single Data Entry via update

Use the update() method to update the article content.
const { data } = await models.post.update({
data: {
title: "Hello World",
body: "Hello World",
},
filter: {
where: {
_id: {
$eq: "xxxx", // It is recommended to pass the _id as data identifier for operations.
},
},
},
});

// Return the number of successfully updated entries.
console.log(data);
// { count: 1}

Creating or Updating Data via upsert

Use the upsert() method to create or update article content.
const post = {
title: "Hello World",
body: "Hello World",
_id: "foo",
};
const { data } = await models.post.upsert({
create: post,
update: post,
filter: {
where: {
_id: {
$eq: post._id,
},
},
},
});
console.log(data);
// Return when creating.
// {
// "count": 0,
// "id": "foo"
// }

// Return when updating.
// {
// "count": 1,
// "id": ""
// }

Updating Multiple Data Entries via updateMany

For example, filter data that is not empty, and use the updateMany() method to update the article content and alias.
const { data } = await models.post.updateMany({
data: {
slug: "hello-world",
body: `
"Hello World" can be translated into the following languages:

English: Hello World Spanish: Hola Mundo French: Bonjour le Monde German: Hallo Welt Italian: Ciao Mondo Portuguese: Olá Mundo Dutch: Hallo Wereld Japanese: こんにちは、世界 (Konnichiwa, Sekai) Korean: 안녕하세요, 세계 (Annyeonghaseyo, Segye)
},
filter: {
where: {
title: {
$nempty: 1, // Data that is not empty.
},
},
},
});

// Return the number of successfully updated entries.
console.log(data);
// {
// "count": 33
// }

Deletion

Deleting a Single Data Entry via delete

Use the delete() method to delete the article with the specified _id.
const { data } = await models.post.delete({
filter: {
where: {
_id: {
$eq: "xxx", // It is recommended to pass the _id as the data identifier for operations.
},
},
},
});

// Return the number of successfully deleted entries.
console.log(data);
// {
// "count": 1
// }

Deleting Multiple Data Entries via deleteMany

For example, use the deleteMany() method to delete articles with the title "Hello World".
const { data } = await models.post.deleteMany({
filter: {
where: {
title: {
$eq: "Hello World",
},
},
},
});

console.log(data);
// Return the number of successfully deleted entries.
// {
// "count": 7
// }

Read

Reading a Single Data Entry via get

Use the get() method to retrieve a specific article.
const { data } = await models.post.get({
filter: {
where: {
_id: {
$eq: _id, // It is recommended to pass the _id as data identifier for operations.
},
},
},
});

// Return the queried data.
console.log(data);
// {
// "owner": "Anonymous(95fblM7nvPi01yQmYxBvBg)",
// "createdAt": 1717488585078,
// "createBy": "Anonymous(95fblM7nvPi01yQmYxBvBg)",
// "updateBy": "Anonymous(95fblM7nvPi01yQmYxBvBg)",
// "_openid": "95fblM7nvPi01yQmYxBvBg",
// "_id": "e2764d2d665ecbc9024b058f1d6b33a4",
// "title": "Hello, World",
// "body":"\\" Hello World\\"can be translated into the following languages: \\n\\n English: Hello World\\n Spanish: Hola Mundo\\n French: Bonjour le Monde\\n German: Hallo Welt\\n Italian: Ciao Mondo\\n Portugal: Olá Mundo\\n Dutch: Hallo Weeld\\n Japanese: , World (Konnichiwa, Sekai)\\n Korean: ,(Annyeonghaseyo, Segye)",
// "slug": "hello-world",
// "updatedAt": 1717490751944
// }

Reading Multiple Data Entries via list

Use the list() method to get all articles. The queried data list records and the total count total will be returned.
const { data } = await models.post.list({
filter: {
where: {},
},
getCount: true, // Enable to get total count.
});

// Return the queried data list `records` and the total count `total`.
console.log(data);
// {
// "records": [
// {
// "owner": "Anonymous(95fblM7nvPi01yQmYxBvBg)",
// "createdAt": 1717488585078,
// "createBy": "Anonymous(95fblM7nvPi01yQmYxBvBg)",
// "updateBy": "Anonymous(95fblM7nvPi01yQmYxBvBg)",
// "_openid": "95fblM7nvPi01yQmYxBvBg",
// "_id": "e2764d2d665ecbc9024b058f1d6b33a4",
// "title": "Hello, World",
// "body":"\\" Hello World\\"can be translated into the following languages: \\n\\n English: Hello World\\n Spanish: Hola Mundo\\n French: Bonjour le Monde\\n German: Hallo Welt\\n Italian: Ciao Mondo\\n Portugal: Olá Mundo\\n Dutch: Hallo Weeld\\n Japanese: , World (Konnichiwa, Sekai)\\n Korean: ,(Annyeonghaseyo, Segye)",
// "slug": "hello-world",
// "updatedAt": 1717490751944
// },
// {
// ...
// },
// ],
// "total": 51
// }


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백