> ## Documentation Index
> Fetch the complete documentation index at: https://www.domo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Partially Update Documents

> Partially updates documents matching a query using MongoDB update operators.

**Supported operators**

`$currentDate` · `$inc` · `$min` · `$max` · `$mul` · `$rename` · `$set` · `$unset` · `$addToSet` · `$pop` · `$pull` · `$pullAll` · `$push`

**Supported modifiers**

`$each` · `$position` · `$slice` · `$sort`

<Note>
  `$setOnInsert` has no effect — partial updates do not perform upserts.
</Note>

See the [MongoDB update operator documentation](https://www.mongodb.com/docs/manual/reference/mql/update/) for full semantics.




## OpenAPI

````yaml /openapi/framework/appdb.yaml put /domo/datastores/v2/collections/{collectionName}/documents/update
openapi: 3.0.0
info:
  title: Domo AppDB API
  version: v1
  description: >
    AppDB API for storing arbitrary JSON documents similar to a NoSQL database.
    This enables storing state within your DomoApp

    with optional syncing to Domo DataSets.


    Three layers provide data storage:

    - **Datastores**: Analogous to a database. A CustomApp has a single
    datastore created automatically.

    - **Collections**: Analogous to a collection in NoSQL or table in relational
    databases.

    - **Documents**: Analogous to documents in NoSQL or table rows in relational
    databases.
servers:
  - url: https://{instance}.domo.com
    description: Domo Instance
    variables:
      instance:
        default: example
        description: Your Domo instance name
security: []
paths:
  /domo/datastores/v2/collections/{collectionName}/documents/update:
    put:
      tags:
        - AppDB API
      summary: Partially Update Documents
      description: >
        Partially updates documents matching a query using MongoDB update
        operators.


        **Supported operators**


        `$currentDate` · `$inc` · `$min` · `$max` · `$mul` · `$rename` · `$set`
        · `$unset` · `$addToSet` · `$pop` · `$pull` · `$pullAll` · `$push`


        **Supported modifiers**


        `$each` · `$position` · `$slice` · `$sort`


        <Note>
          `$setOnInsert` has no effect — partial updates do not perform upserts.
        </Note>


        See the [MongoDB update operator
        documentation](https://www.mongodb.com/docs/manual/reference/mql/update/)
        for full semantics.
      parameters:
        - $ref: '#/components/parameters/CollectionName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PartialUpdateRequest'
            example:
              query:
                content.name:
                  $in:
                    - Hermione Granger
                    - Ron Weasley
              operation:
                $set:
                  content.prefect: true
      responses:
        '200':
          description: Number of documents updated
          content:
            application/json:
              schema:
                type: integer
              example: 2
        '400':
          description: >-
            Bad request. Maybe your JSON is malformed, or you've forgotten to
            include both `query` and `operation` in the body.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                message: >-
                  JSON parse error: Instantiation of [simple type, class
                  com.domo.magnum.model.documents.DocumentUpdate] value failed
                  for JSON property query due to missing (therefore NULL) value
                  for creator parameter query which is a non-nullable type
                status: 400
                statusReason: Bad Request
                toe: APS9BQQ3SQ-HJJ5D-9MRP6
        '403':
          description: >-
            Forbidden. The user does not have the UPDATE_CONTENT permission on
            this collection.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                status: 403
                statusReason: >-
                  status 403 reading
                  DocumentsResourceClient#updateDocument(UUID,UUID,DocumentDefinition)
                toe: BU22GXWMDI-ILY50-5YX28
        '404':
          description: >-
            Collection not found. Verify the collection name is correct (it is
            case-sensitive) and that the collection has been created or
            correctly wired in this app's datastore.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                status: 404
                statusReason: 'DA0088: Invalid collection name: students'
                toe: C7Z7W7ILTW-D2P1Y-9QKHK
      x-codeSamples:
        - lang: JavaScript
          label: domo.js
          source: >-
            const collectionName = 'Students';

            const url =
            `/domo/datastores/v2/collections/${collectionName}/documents/update`;


            // $set — appoint Hermione and Ron as prefects

            domo.put(url, {
              query: { 'content.name': { $in: ['Hermione Granger', 'Ron Weasley'] } },
              operation: { $set: { 'content.prefect': true } }
            }).then(count => console.log(count + ' document(s) updated'));


            // $addToSet — add a course only if Harry isn't already enrolled

            domo.put(url, {
              query: { 'content.name': 'Harry Potter' },
              operation: { $addToSet: { 'content.courses': 'Remedial Potions' } }
            }).then(count => console.log(count + ' document(s) updated'));


            // $push + $each + $sort — enroll Harry in two electives and keep
            the list alphabetical

            domo.put(url, {
              query: { 'content.name': 'Harry Potter' },
              operation: { $push: { 'content.courses': { $each: ['Divination', 'Astronomy'], $sort: 1 } } }
            }).then(count => console.log(count + ' document(s) updated'));


            // $currentDate — stamp the moment Harry was caught out after
            curfew.

            // Note: $currentDate stores a BSON Date, not a string. Query it
            with

            // {"content.caughtAfterCurfewAt": {"$lt": {"$date": "..."}}} not
            plain string comparison.

            domo.put(url, {
              query: { 'content.name': 'Harry Potter' },
              operation: { $currentDate: { 'content.caughtAfterCurfewAt': true } }
            }).then(count => console.log(count + ' document(s) updated'));


            // $pull — Draco drops Defense Against the Dark Arts

            domo.put(url, {
              query: { 'content.name': 'Draco Malfoy' },
              operation: { $pull: { 'content.courses': 'Defense Against the Dark Arts' } }
            }).then(count => console.log(count + ' document(s) updated'));


            // $unset — clear detention records for all Gryffindors at year end

            domo.put(url, {
              query: { 'content.house': 'Gryffindor' },
              operation: { $unset: { 'content.lastDetention': '' } }
            }).then(count => console.log(count + ' document(s) updated'));
        - lang: JavaScript
          label: domo.js v6
          source: >-
            // domo.js v6

            const collectionName = 'Students';


            // $set — appoint Hermione and Ron as prefects

            await domo.appdb.partialUpdate(collectionName,
              { 'content.name': { $in: ['Hermione Granger', 'Ron Weasley'] } },
              { $set: { 'content.prefect': true } }
            ).then(count => console.log(count + ' document(s) updated'));


            // $addToSet — add a course only if Harry isn't already enrolled

            await domo.appdb.partialUpdate(collectionName,
              { 'content.name': 'Harry Potter' },
              { $addToSet: { 'content.courses': 'Remedial Potions' } }
            ).then(count => console.log(count + ' document(s) updated'));


            // $push + $each + $sort — enroll Harry in two electives and keep
            the list alphabetical

            await domo.appdb.partialUpdate(collectionName,
              { 'content.name': 'Harry Potter' },
              { $push: { 'content.courses': { $each: ['Divination', 'Astronomy'], $sort: 1 } } }
            ).then(count => console.log(count + ' document(s) updated'));


            // $currentDate — stamp the moment Harry was caught out after
            curfew.

            // Note: $currentDate stores a BSON Date, not a string. Query it
            with

            // {"content.caughtAfterCurfewAt": {"$lt": {"$date": "..."}}} not
            plain string comparison.

            await domo.appdb.partialUpdate(collectionName,
              { 'content.name': 'Harry Potter' },
              { $currentDate: { 'content.caughtAfterCurfewAt': true } }
            ).then(count => console.log(count + ' document(s) updated'));


            // $pull — Draco drops Defense Against the Dark Arts

            await domo.appdb.partialUpdate(collectionName,
              { 'content.name': 'Draco Malfoy' },
              { $pull: { 'content.courses': 'Defense Against the Dark Arts' } }
            ).then(count => console.log(count + ' document(s) updated'));


            // $unset — clear detention records for all Gryffindors at year end

            await domo.appdb.partialUpdate(collectionName,
              { 'content.house': 'Gryffindor' },
              { $unset: { 'content.lastDetention': '' } }
            ).then(count => console.log(count + ' document(s) updated'));
        - lang: cURL
          label: cURL
          source: |-
            # This API is only available inside a Domo app.
            # Use the JavaScript (domo.js) tab for the correct usage.
        - lang: Python
          label: Python
          source: |-
            # This API is only available inside a Domo app.
            # Use the JavaScript (domo.js) tab for the correct usage.
        - lang: PHP
          label: PHP
          source: |-
            // This API is only available inside a Domo app.
            // Use the JavaScript (domo.js) tab for the correct usage.
        - lang: Go
          label: Go
          source: |-
            // This API is only available inside a Domo app.
            // Use the JavaScript (domo.js) tab for the correct usage.
        - lang: Java
          label: Java
          source: |-
            // This API is only available inside a Domo app.
            // Use the JavaScript (domo.js) tab for the correct usage.
        - lang: Ruby
          label: Ruby
          source: |-
            # This API is only available inside a Domo app.
            # Use the JavaScript (domo.js) tab for the correct usage.
components:
  parameters:
    CollectionName:
      name: collectionName
      in: path
      required: true
      description: The name given to the collection in the manifest. Case-sensitive.
      schema:
        type: string
  schemas:
    PartialUpdateRequest:
      type: object
      required:
        - query
        - operation
      properties:
        query:
          type: object
          additionalProperties: true
          description: MongoDB query to match documents
        operation:
          type: object
          additionalProperties: true
          description: MongoDB update operation
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
          description: >-
            A plain-English explanation of the error. Present on some errors but
            not all.
        status:
          type: integer
          description: The HTTP error code
        statusReason:
          type: string
          description: >-
            A human-readable error message, sometimes including nested error
            detail
        toe:
          type: string
          description: >-
            Thread of Execution; a unique identifier that Support can use to
            find more info about your problem
      example:
        status: 404
        statusReason: 'DA0088: Invalid collection name: Students'
        toe: FTYRJMBLKD-5HB2Z-H6W8A

````