查询单个文档
GET/collections/:collectionName/documents/:docId
根据文档 _id 查询单个文档。支持字段过滤(projection)和事务中查询。如果文档不存在,返回 404。
Request
Path Parameters
collectionName stringrequired
集合名称
docId stringrequired
文档 ID(支持 ObjectId 字符串和普通字符串)
Query Parameters
projection string
字段过滤(JSON 字符串),如 {"name":1,"email":1}
transactionId string
事务 ID
Responses
- 200
- 404
查询成功
- application/json
- Schema
- Example (from schema)
- Example
Schema
object
{}
{
"_id": {
"$oid": "507f1f77bcf86cd799439011"
},
"name": "John Doe",
"age": {
"$numberInt": "30"
},
"email": "john@example.com"
}
文档不存在
- application/json
- Schema
- Example (from schema)
- Example
Schema
code string
错误码
message string
错误信息
request_id string
请求唯一 ID
{
"code": "INVALID_PARAM",
"message": "param.query can't be empty",
"request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
{
"code": "DOCUMENT_NOT_FOUND",
"message": "Document not found",
"request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
Loading...