Insert Documents

POST /action/insertMany

Insert multiple documents into a collection.

Body

  • dataSource string Required

    The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

  • database string Required

    The name of a database in the specified data source.

  • collection string Required

    The name of a collection in the specified database.

  • documents array[object] Required

    A list of documents to insert into the collection.

Body

  • dataSource string Required

    The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

  • database string Required

    The name of a database in the specified data source.

  • collection string Required

    The name of a collection in the specified database.

  • documents array[object] Required

    A list of documents to insert into the collection.

Responses

  • Inserted

    Hide response attribute Show response attribute object
    • insertedIds array[string]

      A list of the _id values of the inserted documents.

    Hide response attribute Show response attribute object
    • insertedIds array[string]

      A list of the _id values of the inserted documents.

  • 400 application/json

    The request was malformed or incomplete.

    One of:
  • 401 application/json

    The authenticated user does not have permission to access this endpoint.

    Hide response attributes Show response attributes object

    Indicates that no user matched the provided authentication credentials.

    • error string

      A message that describes the error.

      Value is invalid session: error finding user for endpoint.

    • error_code string

      The error type.

      Value is InvalidSession.

POST /action/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"
      }
    ]
  }'
Request example
{
  "database": "todo",
  "documents": [
    {
      "text": "Mop the floor",
      "status": "open"
    },
    {
      "text": "Clean the windows",
      "status": "open"
    }
  ],
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
Request example
{
  "database": "todo",
  "documents": [
    {
      "text": "Mop the floor",
      "status": "open"
    },
    {
      "text": "Clean the windows",
      "status": "open"
    }
  ],
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
Response examples (200)
{
  "insertedIds": [
    "61935189ec53247016a623c9",
    "61935189ec53247016a623ca"
  ]
}
Response examples (200)
{
  "insertedIds": [
    {
      "$oid": "61935189ec53247016a623c9"
    },
    {
      "$oid": "61935189ec53247016a623ca"
    }
  ]
}
Response examples (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"
}
Response examples (401)
{
  "error": "invalid session: error finding user for endpoint",
  "error_code": "InvalidSession",
  "link": "string"
}