All Products
Search
Document Center

ApsaraDB for MongoDB:DescribeAuditRecords

Last Updated:Oct 08, 2026

Queries the audit logs of a MongoDB instance.

Operation description

  • The audit log feature must be enabled for the instance before you call this operation. Otherwise, the returned audit log content is empty.

  • This operation applies to instances of the General-purpose local disk and Dedicated local disk specification types.

  • This operation can be called up to 30 times per minute. Calls that exceed this limit are throttled. Do not call this operation at a high frequency. If high-frequency calls are required, use a Logstore. For more information, see Manage a Logstore.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dds:DescribeAuditRecords

get

*dbinstance

acs:dds:{#regionId}:{#accountId}:dbinstance/{#dbinstanceId}

None None

Request parameters

Parameter

Type

Required

Description

Example

DBInstanceId

string

Yes

The instance ID.

Note

If you specify a sharded cluster instance ID for this parameter, you must also specify the NodeId parameter.

dds-bp12c5b040dc****

NodeId

string

No

Instance ID of a mongos node or shard node in the sharded cluster instance.

Note

This parameter is available only when DBInstanceId is set to instance ID of a sharded cluster instance.

d-bp128a003436****

StartTime

string

Yes

The start time of the query. Specify the time in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.

2019-03-13T12:11:14Z

EndTime

string

Yes

The end time of the query. The end time must be later than the start time. Specify the time in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.

Note

The time range between the end time and the start time cannot exceed 24 hours. If the time range exceeds 24 hours, the call fails.

2019-03-13T13:11:14Z

Database

string

No

The name of the database. The default value is all databases.

database****

User

string

No

The database account. The default value is all accounts.

test

Form

string

No

The display format of the returned audit records. Valid values:

  • File: Triggers the generation of an audit log file. If you set this parameter to this value, only common parameters are returned.

  • Stream (default): Returns a data stream.

Note

The File value is deprecated.

Valid values:

  • Stream :

    returns a data stream.

  • File :

    generates an audit log file.

Stream

QueryKeywords

string

No

The keywords to query. Separate multiple keywords with spaces. You can specify a maximum of 10 keywords.

slow

LogicalOperator

string

No

The logical operator for keyword search. The default value is and.

Valid values:

  • or :

    matches any keyword.

  • and :

    matches all keywords.

and

PageSize

integer

No

The number of records per page. Valid values: 30 (default), 50, and 100.

30

PageNumber

integer

No

The page number. The value must be greater than 0 and cannot exceed the maximum value of the Integer type. Default value: 1.

1

OrderType

string

No

The order in which the queried slow logs are sorted by time. Valid values:

  • asc: sorts results in ascending order by time.

  • desc: sorts results in descending order by time.

Valid values:

  • asc :

    sorts results in ascending order by time.

  • desc :

    sorts results in descending order by time.

asc

Response elements

Element

Type

Description

Example

object

The total number of records.

TotalRecordCount

integer

The total number of records.

40

PageRecordCount

integer

The maximum number of records on the current page.

30

RequestId

string

The request ID.

3278BEB8-503B-4E46-8F7E-D26E040C9769

PageNumber

integer

The page number.

1

Items

object

SQLRecord

array<object>

The list of audit log details.

object

The instance information.

HostAddress

string

The client IP address.

11.xxx.xxx.xxx

TableName

string

The name of the MongoDB collection.

C1

ReturnRowCounts

integer

The number of returned records.

2

DBName

string

The name of the database.

test123

ExecuteTime

string

The time when the statement was executed. The time is in the yyyy-MM-ddTHH:mm:ssZ format. The time is in UTC.

2019-03-11T03:30:27Z

ThreadID

string

The thread ID.

140682188297984

TotalExecutionTimes

integer

The execution duration, in microseconds.

700

Syntax

string

The executed statement.

{ \"atype\" : \"createCollection\", \"param\" : { \"ns\" : \"123.test1\" }, \"result\": \"OK\" }

AccountName

string

The name of the database account.

test

Examples

Success response

JSON format

{
  "TotalRecordCount": 40,
  "PageRecordCount": 30,
  "RequestId": "3278BEB8-503B-4E46-8F7E-D26E040C9769",
  "PageNumber": 1,
  "Items": {
    "SQLRecord": [
      {
        "HostAddress": "11.xxx.xxx.xxx",
        "TableName": "C1",
        "ReturnRowCounts": 2,
        "DBName": "test123",
        "ExecuteTime": "2019-03-11T03:30:27Z",
        "ThreadID": "140682188297984",
        "TotalExecutionTimes": 700,
        "Syntax": "{ \\\"atype\\\" : \\\"createCollection\\\", \\\"param\\\" : { \\\"ns\\\" : \\\"123.test1\\\" }, \\\"result\\\": \\\"OK\\\" }",
        "AccountName": "test"
      }
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidStartTime.Format Specified start time is not valid. The specified start time is invalid.
400 InvalidEndTime.Format Specified end time is not valid. The specified EndTime parameter is invalid. Specify a valid end time point in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC. The end time must be later than the start time.
400 InvalidEndTime.Invalid Specified end time is before this service active time.
400 InvalidParameterCombination The end time must be greater than the start time. The end time must be later than the start time.
400 InvalidQueryKeyword.Format Specified Query Keyword is not valid.
400 InvalidDatabase.Format Specified Database is not valid.
400 InvalidQueryTime.Format Specified query time is not valid. StartTime or EndTime parameter is null or illegal.
403 IncorrectSQLLogActiveStatus Current DB instance SQL log active status does not support this operation.
403 LogApiFrequencyExceeded Exceeding the allowed frequency of log api.
403 ConcurrentTaskExceeded Concurrent task exceeding the allowed amount.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.