插入文档

发布 /action/insertMany

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

body

  • dataSource 字符串 必需

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

  • database 字符串 必需

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

  • 集合 字符串 必需

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

  • 文档 大量[对象] 必需

    要插入到集合中的文档列表。

body

  • dataSource 字符串 必需

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

  • database 字符串 必需

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

  • 集合 字符串 必需

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

  • 文档 大量[对象] 必需

    要插入到集合中的文档列表。

响应

  • Inserted

    隐藏响应属性 显示响应属性 对象
    • InsertedIds array[string]

      已插入文档的 _id 值的列表。

    隐藏响应属性 显示响应属性 对象
    • InsertedIds array[string]

      已插入文档的 _id 值的列表。

  • 400 application/json

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

    以下之一:
  • 401 application/json

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

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

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

    • 错误 字符串

      描述错误的消息。

      值为 invalid session: error finding user for endpoint

    • error_code 字符串

      错误类型。

      值为 InvalidSession

POST /动作/insertMany
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/insertMany" \
  -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",
    "documents": [
      {
        "status": "open",
        "text": "Mop the floor"
      },
      {
        "status": "open",
        "text": "Clean the windows"
      }
    ]
  }'
请求示例
{
  "database": "todo",
  "documents": [
    {
      "text": "Mop the floor",
      "status": "open"
    },
    {
      "text": "Clean the windows",
      "status": "open"
    }
  ],
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
请求示例
{
  "database": "todo",
  "documents": [
    {
      "text": "Mop the floor",
      "status": "open"
    },
    {
      "text": "Clean the windows",
      "status": "open"
    }
  ],
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
响应示例 (200)
{
  "insertedIds": [
    "61935189ec53247016a623c9",
    "61935189ec53247016a623ca"
  ]
}
响应示例 (200)
{
  "insertedIds": [
    {
      "$oid": "61935189ec53247016a623c9"
    },
    {
      "$oid": "61935189ec53247016a623ca"
    }
  ]
}
响应示例 (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"
}