查找文档

发布 /action/find

查找多个与查询匹配的文档。

body

  • dataSource 字符串 必需

    链接的 MongoDB Atlas 数据源的名称。它通常为 "mongodb-atlas",但如果您在创建数据源时选择了不同的名称,则在应用程序中可能具有不同的名称。

  • database 字符串 必需

    指定的数据源中的数据库名称。

  • 集合 字符串 必需

    指定的数据库中的集合名称。

  • 筛选器 对象

    匹配文档的 MongoDB 查询筛选条件。有关 Data API 支持的所有查询运算符的列表,请参阅查询运算符

  • 投影 对象

    操作返回的匹配文档的 MongoDB 投影

    隐藏投影属性 显示投影属性 对象
    • * 数字 additionalProperties

      值为 01

  • sort 对象

    指示排序的字段名称和方向的 MongoDB 排序表达式

  • limit 数字

    响应中包含的匹配文档的最大数量。

  • 跳过 数字

    要从响应中忽略的匹配文档的数量。

body

  • dataSource 字符串 必需

    链接的 MongoDB Atlas 数据源的名称。它通常为 "mongodb-atlas",但如果您在创建数据源时选择了不同的名称,则在应用程序中可能具有不同的名称。

  • database 字符串 必需

    指定的数据源中的数据库名称。

  • 集合 字符串 必需

    指定的数据库中的集合名称。

  • 筛选器 对象

    匹配文档的 MongoDB 查询筛选条件。有关 Data API 支持的所有查询运算符的列表,请参阅查询运算符

  • 投影 对象

    操作返回的匹配文档的 MongoDB 投影

    隐藏投影属性 显示投影属性 对象
    • * 数字 additionalProperties

      值为 01

  • sort 对象

    指示排序的字段名称和方向的 MongoDB 排序表达式

  • limit 数字

    响应中包含的匹配文档的最大数量。

  • 跳过 数字

    要从响应中忽略的匹配文档的数量。

响应

  • Found

    隐藏响应属性 显示响应属性 对象
    • 文档 大量[对象]

      与指定过滤匹配的文档列表。

    隐藏响应属性 显示响应属性 对象
    • 文档 大量[对象]

      与指定过滤匹配的文档列表。

  • 400 application/json

    请求格式不正确或不完整。

    以下之一:
  • 401 application/json

    经过身份验证的用户没有访问权限此端点的权限。

    隐藏响应属性 显示响应属性 对象

    表示没有用户与提供的身份验证凭证匹配。

    • 错误 字符串

      描述错误的消息。

      值为 invalid session: error finding user for endpoint

    • error_code 字符串

      错误类型。

      值为 InvalidSession

POST /动作/find
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/find" \
  -X POST \
  -H "apiKey: $API_KEY" \
  -H 'Content-Type: application/ejson' \
  -H "Accept: application/json" \
  -d '{
    "dataSource": "mongodb-atlas",
    "database": "learn-data-api",
    "collection": "tasks",
    "filter": {
      "status": "complete"
    },
    "sort": { "completedAt": 1 },
    "limit": 10
  }'
请求示例
{
  "sort": {
    "completedAt": 1
  },
  "limit": 10,
  "filter": {
    "status": "complete"
  },
  "database": "todo",
  "collection": "tasks",
  "dataSource": "mongodb-atlas",
  "projection": {
    "text": 1,
    "completedAt": 1
  }
}
请求示例
{
  "sort": {
    "completedAt": 1
  },
  "limit": 10,
  "filter": {
    "status": "complete"
  },
  "database": "todo",
  "collection": "tasks",
  "dataSource": "mongodb-atlas",
  "projection": {
    "text": 1,
    "completedAt": 1
  }
}
响应示例 (200)
{
  "documents": [
    {
      "_id": "6193504e1be4ab27791c8133",
      "text": "Do the dishes",
      "completedAt": "2022-05-16T20:22:01.104Z"
    },
    {
      "_id": "6194604e1d38dc33792d8257",
      "text": "Feed the dog",
      "completedAt": "2022-05-17T05:12:42.828Z"
    }
  ]
}
响应示例 (200)
{
  "documents": [
    {
      "_id": {
        "$oid": "6193504e1be4ab27791c8133"
      },
      "text": "Do the dishes",
      "completedAt": {
        "$date": {
          "$numberLong": "1652732521104"
        }
      }
    },
    {
      "_id": {
        "$oid": "6194604e1d38dc33792d8257"
      },
      "text": "Feed the dog",
      "completedAt": {
        "$date": {
          "$numberLong": "1652764362828"
        }
      }
    }
  ]
}
响应示例 (400)
{
  "error": "no authentication methods were specified",
  "error_code": "InvalidParameter",
  "link": "string"
}
{
  "error": "must specify some form of authentication (either email+password, api-key, or jwt) in the request header or body",
  "error_code": "MissingParameter",
  "link": "string"
}
响应示例 (401)
{
  "error": "invalid session: error finding user for endpoint",
  "error_code": "InvalidSession",
  "link": "string"
}