Update One Document

POST /action/updateOne

Update a single document in 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.

  • filter object

    A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

  • update object Required

    A MongoDB update expression to apply to matching documents. For a list of all update operators that the Data API supports, see Update Operators.

  • upsert boolean

    When true, if the update filter does not match any existing documents, then insert a new document based on the filter and the specified update operation.

    Default value is false.

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.

  • filter object

    A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

  • update object Required

    A MongoDB update expression to apply to matching documents. For a list of all update operators that the Data API supports, see Update Operators.

  • upsert boolean

    When true, if the update filter does not match any existing documents, then insert a new document based on the filter and the specified update operation.

    Default value is false.

Responses

  • Updated

    Hide response attributes Show response attributes object
    • matchedCount Required

      The number of documents matched by the query filter.

    • modifiedCount Required

      The number of matched documents that were modified.

    • upsertedId string

      The _id value of the upserted document.

    Hide response attributes Show response attributes object
    • matchedCount Required

      The number of documents matched by the query filter.

    • modifiedCount Required

      The number of matched documents that were modified.

    • upsertedId string

      The _id value of the upserted document.

  • 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/updateOne
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/updateOne" \
  -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": {
      "_id": { "$oid": "64224f4d089104f1766116a5" }
    },
    "update": {
      "$set": {
        "status": "complete",
        "completedAt": { "$date": { "$numberLong": "1680105272788" } }
      }
    }
  }'
Request example
{
  "filter": {
    "_id": {
      "$oid": "642f1bb5cee4111898828bf6"
    }
  },
  "update": {
    "$set": {
      "status": "complete"
    }
  },
  "upsert": false,
  "database": "todo",
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
Request example
{
  "filter": {
    "_id": {
      "$oid": "642f1bb5cee4111898828bf6"
    }
  },
  "update": {
    "$set": {
      "status": "complete"
    }
  },
  "upsert": false,
  "database": "todo",
  "collection": "tasks",
  "dataSource": "mongodb-atlas"
}
Response examples (200)
{
  "matchedCount": 1,
  "modifiedCount": 1
}
Response examples (200)
{
  "matchedCount": {
    "$numberInt": "1"
  },
  "modifiedCount": {
    "$numberInt": "1"
  }
}
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"
}