插入一个文档

发布 /action/insertOne

将单个文档插入到集合中。

body

  • dataSource 字符串 必需

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

  • database 字符串 必需

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

  • 集合 字符串 必需

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

  • 文档 对象 必需

    要插入到集合中的文档。

body

  • dataSource 字符串 必需

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

  • database 字符串 必需

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

  • 集合 字符串 必需

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

  • 文档 对象 必需

    要插入到集合中的文档。

响应

  • Inserted

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

      插入文档的_id值。

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

      插入文档的_id值。

  • 400 application/json

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

    以下之一:
  • 401 application/json

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

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

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

    • 错误 字符串

      描述错误的消息。

      值为 invalid session: error finding user for endpoint

    • error_code 字符串

      错误类型。

      值为 InvalidSession

POST /动作/insertOne
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/insertOne" \
  -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",
    "document": {
      "status": "open",
      "text": "Do the dishes"
    }
  }'
请求示例
{
  "database": "todo",
  "document": {
    "text": "Do the dishes",
    "status": "open${{ env.BUNDLED_SPEC_FILEPATH }}"
  },
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
请求示例
{
  "database": "todo",
  "document": {
    "text": "Do the dishes",
    "status": "open"
  },
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
响应示例 (200)
{
  "insertedId": "6193504e1be4ab27791c8133"
}
响应示例 (200)
{
  "insertedId": {
    "$oid": "6193504e1be4ab27791c8133"
  }
}
响应示例 (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"
}