tencent cloud

Data Model SDK

Download
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-05-13 11:35:19

Querying Data

Initializing SDK

import cloudbase from "@cloudbase/js-sdk";

const app = cloudbase.init({
env: "your-env-id", // Replace with your environment id
});

const models = app.models;

Querying a Single Record

Query a single record by specifying conditions.
models.modelName.get(options);
modelName: Data model name
options: Query parameters

options Parameter Description

For details on specific query parameters, see the Query Parameters document.
Parameter
Type
Required
Description
filter.where
object
No
query conditions
select
object
Yes
Specifying the fields to return

Sample Code

// Query the record with _id 'todo-id-123' from the todo data model.
const todo = await models.todo.get({
filter: {
where: {
_id: {
$eq: "todo-id-123",
},
},
},
select: {
$master: true, // Return all fields
},
});

console.log("Query result:", todo.data);

Returned Result

{
data: {
records: [{
_id: "todo-id-123",
title: "Server-side Task",
completed: false,
// ... Other fields
}],
total: 1
}
}

Querying Multiple Records

Query multiple records, supporting conditional filtering, sorting, pagination, and more.
models.modelName.list(options);
modelName: Data model name
options: Query parameters

options Parameter Description

For details on specific query parameters, see the Query Parameters document.
Parameter
Type
Required
Description
filter.where
object
No
query conditions
select
object
Yes
Specifying the fields to return

Sample Code

// Query records from the todo data model where completed is false.
const todos = await models.todo.list({
filter: {
where: {
completed: {
$eq: false
},
},
},
});

console.log("Query result:", todos.data);

Returned Result

{
data: {
records: [{
_id: "todo-id-1",
title: "Task 1",
completed: false
},
{
_id: "todo-id-2",
title: "Task 2",
completed: false
}
],
total: 2
}
}


도움말 및 지원

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

피드백