Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
Huawei Cloud Astro Canvas
Huawei Cloud Astro Zero
CodeArts Governance
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance (CCI)
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Cloud Transformation
Well-Architected Framework
Cloud Adoption Framework
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Querying Data by Condition

Updated on 2025-03-21 GMT+08:00

Function

This API is used to query data by condition.

URI

POST Huawei Cloud Astro Zero domain name/u-route/baas/data/v1.0/query/{objectName}?base=X&fields=f1,f2

Table 1 URI parameters

Parameter

Mandatory

Type

Description

objectName

Yes

String

Explanation

Data object name. For details, see Logging In to the Application Designer. You can access the application designer and choose Data > Object to view data object names.

Constraints

None

Value

1–80 characters

Default value

None

base

No

String

Explanation

Query parameter, which is used to distinguish the data passed by objectName.

Constraints

None

Value

The options are as follows:

  • I: ID of the corresponding object.
  • N: An object name is transferred.

Default value

None

fields

No

Array

Explanation

Field displayed in an object. Set this parameter to the unique ID of a field. Use commas (,) to separate multiple fields. If this parameter is specified, only the specified fields and necessary information (for example, data record owner and the owner ID) are returned. If this parameter is left unspecified, the entire data record is returned.

  1. Access the application designer by referring to Logging In to the Application Designer.
  2. Choose Data > Object, click over the object, and choose Details.
  3. On the Fields tab page of the object details page, view the unique identifiers of fields.

Constraints

None

Request Parameters

Table 2 Request parameters

Parameter

Mandatory

Type

Description

condition

No

Object

Explanation

Query condition. If this parameter is left unspecified, all object data is queried. This parameter contains the following elements:

  • conjunction: number of conditions to meet.
    • AND: All conditions must be met.
    • OR: At least one condition must be met.
  • conditions: array of conditions. If this parameter is left unspecified, all object data is queried. If this parameter is specified, each element contains the following fields:
    • field: field name.
    • operator: operator, which can be: eq indicates equal to, ne indicates not equal to, gt indicates greater than, lt indicates less than, ge indicates greater than or equal to, and le indicates less than or equal to.
    • value: comparison value.
  • relation: The array contains parents (upward query) and children (downward query).

    The parents field contains the condition array and relatedField (name of the associated field). The children field contains the condition array and relationName (name of the associated field).

Constraints

None

relation

No

Object

Explanation

Associated query, including parents (upward query) and children (downward query).

The parents field contains the condition array and relatedField (name of the associated field). The children field contains the condition array and relationName (name of the associated field).

The condition array contains conjunction, conditions, and relation. The parameter description is the same as that of condition.

{  
    //Upward query
    parents: [//Level-1 parent object
      {
        relatedField: "CarHolder__CST", // Current object field (Lookup/MasterDetail type), which is used to determine the parent object
        options: {
          fields: ["id", "name", "Age__CST"] // Field to be queried of the parent object
        },
        parents: [// (Optional) Level-2 parent object
          {
            relatedField: "cust__CST," // Parent object field (Lookup/MasterDetail type), which is used to determine the grandparent object
            options: {
              fields: ["id", "name", "Email__CST"] // Field to be queried of the grandparent object
            }
          }
        ]
      }
    ],
    //Downward query
    childs: [//Level-1 child object
      {
        relationName: "Contacts," // Child object relationship name (specified when Lookup/MasterDetail is defined for a child object). The child object is determined based on the relationship name.
        options: {
        fields: ["id", "name", "Age__CST", "cust__CST"] // Child object field to be queried
      },
      childs: [// (Optional) Level-2 child object
        {
            relationName: "ContactCars", // Relationship name of the grandchild object
            options: {
              fields: ["id", "name", "Price__CST", "CarHolder__CST"] // Grandchild object field to be queried
            }
        }
      ]
      }
    ]
  }

Constraints

None

options

No

Object

Explanation

Additional option, which is used to perform operations on the query result.

  • orderBy: used to sort the query result by the value of a specific field. The value can be asc (ascending order) or desc (descending order).
    options: {
                orderby: [
                    {
                        field: "name",
                        order: db.Order.desc
                    }
                ],
              }
  • groupby: used to group the query result based on specified fields.
    options: {
                groupby: [
                    {
                        field: "name",
                    }
                ],
              }
  • distinct: used to deduplicate the query result.
    options: {
                distinct: true,
              }
  • skip and limit: limit specifies the total number of records to be returned, and skip specifies the ID of the first record to be returned. They are used together to limit the number of returned records.
    {
              options: {
                skip: 100,
                limit: 100
              }
          }

Constraints

None

Response Parameters

Table 3 Response parameters

Parameter

Type

Description

resCode

String

Explanation

Return code.

Value

If the request is successful, 0 is returned. For details about other error codes, see Error Codes.

resMsg

String

Explanation

Message returned.

Value

If the request is successful, Success is returned. In other cases, an error message is returned.

result

Array

Explanation

Returned object data.

count

number

Explanation

Total number of records that meet the conditions in the object.

Value

None

Example Request

To query the number of records where name is zhang in the TestProject__testForObject1__CST object and return three records sorted in descending order by the TestProject__length__CST field, send the following request:
POST https://Huawei Cloud Astro Zero domain names /u-route/baas/data/v1.0/query/TestProject__testForObject1__CST?base=N
  
 {"condition": {
        "conjunction": "AND",
        "conditions": [
            {
                "field": "name",
                "operator": "eq",
                "value": "zhang"
            }
        ]
    },
    "options": {
        "orderby": [
            {
                "field": "TestProject__length__CST",
                "order": "desc"
            }
        ],
        "limit": 3
    }
}

Example Response

{
    "resCode": "0",
    "resMsg": "Success",
    "result": [
        {
            "TestProject__age__CST": null,
            "TestProject__length__CST": "888",
            "TestProject__name__CST": null,
            "createdBy": "10gd000000SDzgxNSckK",
            "createdBy.__objectType": "User",
            "createdBy.name": "test0xx",
            "createdDate": "2020-05-29 12:50:59",
            "currencyIsoCode": "",
            "id": "cglE000000aMGHkvmhmb",
            "installedPackage": null,
            "lastModifiedBy": "10gd000000SDzgxNSckK",
            "lastModifiedBy.__objectType": "User",
            "lastModifiedBy.name": "test0xx",
            "lastModifiedDate": "2020-05-29 12:50:59",
            "name": "zhang",
            "owner": "10gd000000SDzgxNSckK",
            "owner.__objectType": "User",
            "owner.name": "test0xx"
        },
        {
            "TestProject__age__CST": null,
            "TestProject__length__CST": "456",
            "TestProject__name__CST": null,
            "createdBy": "10gd000000SDzgxNSckK",
            "createdBy.__objectType": "User",
            "createdBy.name": "test0xx",
            "createdDate": "2020-05-29 12:50:59",
            "currencyIsoCode": "",
            "id": "cglE000000aMGHkvmhma",
            "installedPackage": null,
            "lastModifiedBy": "10gd000000SDzgxNSckK",
            "lastModifiedBy.__objectType": "User",
            "lastModifiedBy.name": "test0xx",
            "lastModifiedDate": "2020-05-29 12:50:59",
            "name": "zhang",
            "owner": "10gd000000SDzgxNSckK",
            "owner.__objectType": "User",
            "owner.name": "test0xx"
        },
        {
            "TestProject__age__CST": null,
            "TestProject__length__CST": "17",
            "TestProject__name__CST": null,
            "createdBy": "10gd000000SDzgxNSckK",
            "createdBy.__objectType": "User",
            "createdBy.name": "test0xx",
            "createdDate": "2020-05-29 12:43:11",
            "currencyIsoCode": "",
            "id": "cglE000000aMFjB9ipAu",
            "installedPackage": null,
            "lastModifiedBy": "10gd000000SDzgxNSckK",
            "lastModifiedBy.__objectType": "User",
            "lastModifiedBy.name": "test0xx",
            "lastModifiedDate": "2020-05-29 12:43:11",
            "name": "zhang",
            "owner": "10gd000000SDzgxNSckK",
            "owner.__objectType": "User",
            "owner.name": "test0xx"
        }
    ],
    "count": 5
}

Status Code

See Status Codes.

Error Code

See Error Codes.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback