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

# Update Records by Criteria

> Update existing records by criteria.

#### Recipes

<AccordionGroup>
  <Accordion title="Update records by criteria with API key">
    <Steps>
      <Step title="1. Use 'Authorization' header to pass API key">
        ```curl {3} theme={null}
        curl -X PUT \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "game_mode_name":"beta testing",
          "search_criteria":{
            "expert_mode":"false",
            "progress":{
              "gt":"0.2"
            }
          }
        }' \
        https://api.quickblox.com/data/ScoreTable/by_criteria.json
        ```
      </Step>

      <Step title="2. As a result, the API returns the number of updated records.">
        ```json theme={null}
        {
          "class_name": "ScoreTable",
          "skip": 0,
          "limit": 100,
          "total_found": 2,
          "items": [
            {
              "_id": "5d866b53a28f9a5ad51cb562",
              "_parent_id": null,
              "completed_levels": [
                1,
                2,
                3,
                4
              ],
              "created_at": 1569090387,
              "date": "2019-09-21T21:21:00Z",
              "expert_mode": false,
              "game_mode_name": "beta testing",
              "progress": 0.23,
              "score_value": 705,
              "updated_at": 1569177307,
              "user_avatar": null,
              "user_id": 96753878,
              "user_location": [
                11.13,
                45.52
              ],
              "permissions": {
                "read": {
                  "access": "open"
                },
                "update": {
                  "access": "owner"
                },
                "delete": {
                  "access": "owner"
                }
              }
            },
            {
              "_id": "5d867291a0eb473ed96099c4",
              "_parent_id": null,
              "completed_levels": [
                1,
                2,
                3,
                4,
                5,
                6
              ],
              "created_at": 1569092241,
              "date": "2019-09-21T21:25:00Z",
              "expert_mode": false,
              "game_mode_name": "beta testing",
              "progress": 0.42,
              "score_value": 3021,
              "updated_at": 1569177307,
              "user_avatar": null,
              "user_id": 96753878,
              "user_location": null,
              "permissions": {
                "read": {
                  "access": "open"
                },
                "update": {
                  "access": "owner"
                },
                "delete": {
                  "access": "owner"
                }
              }
            }
          ]
        }
        ```
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

You can update records by criteria using the `search_criteria` operator. **All** parameters that
are not included in the search criteria will be considered as parameters for updating the fields
of records found by the search criteria.

You can use all search operators listed below the request.

**Search operators**

The request can contain all, some or none of the next search operators:

| Operator | Description                                                                                                                                                                                                                                                                                       |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| lt       | **Less Than** operator  <br />  <br />Types: integer, float  <br />  <br />Example:  <br />score\_value\[lt]=1000                                                                                                                                                                                 |
| lte      | **Less Than or Equal to** operator  <br />  <br />Types: integer, float  <br />  <br />Example:  <br />score\_value\[lte]=850                                                                                                                                                                     |
| gt       | **Greater Than** operator  <br />  <br />Types: integer, float  <br />  <br />Example:  <br />bonus\_count\[gt]=2.45                                                                                                                                                                              |
| gte      | **Greater Than or Equal to** operator  <br />  <br />Types: integer, float  <br />  <br />Example:  <br />bonus\_count\[gte]=56.443                                                                                                                                                               |
| ne       | **Not Equal to** operator  <br />  <br />Types: integer, float, string, boolean  <br />  <br />Example:  <br />game\_mode\_name\[ne]=ctf                                                                                                                                                          |
| in       | **Contained IN array** operator  <br />  <br />Types: integer, float, string  <br />  <br />Example:  <br />game\_mode\_name\[in]=deathmatch,rage                                                                                                                                                 |
| nin      | **Not contained IN array** operator  <br />  <br />Types: integer, float, string  <br />  <br />Example:  <br />game\_mode\_name\[nin]=survivor,crazy\_nightmare                                                                                                                                  |
| all      | **ALL contained IN array** operator  <br />  <br />Types: array  <br />  <br />Example:  <br />game\_modes\[all]=survivor,crazy                                                                                                                                                                   |
| or       | **OR** operator  <br />  <br />Types: integer, float, string  <br />  <br />Example:  <br />name\[or]=sam,tim  <br />name\[or]=sam\&lastname\[or]=johnson  <br />  <br />Will return records with name `sam` **or** `tim`.  <br />Will return records with name `sam` **or** last name `johnson`. |
| ctn      | **Contains** substring operator  <br />  <br />Types: string  <br />  <br />Example:  <br />username\[ctn]=son  <br />  <br />Will return all records where `username` field **contains** `son` substring.                                                                                        |
| near     | Types: location  <br />  <br />Example:  <br />mylocation\[near]=25.32,44.551;1000  <br />  <br />Search records in a specific radius with  <br />the current position in meters.  <br />Format: `{field_name}[near]=longitude,latitude;radius`.                                                  |

**Allowed permissions**

| Permission         | Syntax                                                                                                                      | Example                                                                               |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| Open               | permissions.\<CRUD\_operation>.access                                                                                       | permissions.read.access=open                                                          |
| Owner              | permissions.\<CRUD\_operation>.access                                                                                       | permissions.read.access=owner                                                         |
| Open for users IDs | permissions.\<CRUD\_operation>.access=open\_for\_users\_ids permissions.\<CRUD\_operation>.ids=id\_1,id\_2,id\_3,…          | permissions.update.access=open\_for\_users\_ids permissions.update.ids=3,12           |
| Open for groups    | permissions.\<CRUD\_operation>.access=open\_for\_groups permissions.\<CRUD\_operation>.groups=group\_name\_1,group\_name\_2 | permissions.delete.access=open\_for\_groups permissions.delete.groups=experience,rate |

#### Path Parameters

<ParamField path="class_name" type="string" required>
  Custom object class name.
</ParamField>

#### Body Parameters

<ParamField body="{custom_field_N}" type="string">
  Update value to the field defined in Custom Object class.
</ParamField>

<ParamField body="search_criteria" type="object">
  <Expandable title="Search criteria object">
    <ParamField body="{custom_field_N}" type="string">
      Search records with the field that contains the specified value.
    </ParamField>

    <ParamField body="{custom_field_M}" type="object">
      <Expandable title="{custom_field_M} object">
        <ParamField body="{search_operator}" type="string">
          Search a record with the field that contains a value according to the specified value and operator.
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="permissions" type="string">
  Record permissions. Format: <br />
  `permission.<CRUD_operation>.access=<value>` <br />
  `permission.<CRUD_operation>.<option>=<value>`

  CRUD operations: `create`, `read`, `update`, `delete`. <br />
  CRUD access values: `open`, `owner`, `open_for_users_ids`, `open_for_groups`. <br />
  CRUD options: `ids`, `groups`.
</ParamField>

#### Headers

<ParamField header="QB-Token" type="string" required> A user or application session token. See [Authentication](/reference/authentication) page to learn more about session tokens. Must be used either QB-Token or Authorization. </ParamField>

<ParamField header="Authorization" type="string" default="ApiKey {your_api_key}">
  API key from Dashboard. Expected format: `ApiKey {your_api_key}`. Must be used
  either QB-Token or Authorization.
</ParamField>

<ParamField header="On-Behalf-Of" type="string">
  User ID. The user ID of the user on whose behalf the request is being made.
</ParamField>

#### Responses

<AccordionGroup>
  <Accordion title="200">
    A successful response

    <ResponseField name="class_name" type="string" />

    <ResponseField name="skip" type="integer" />

    <ResponseField name="limit" type="integer" />

    <ResponseField name="total_found" type="integer" />

    <ResponseField name="items" type="array of objects">
      <Expandable title="properties">
        <ResponseField name="_id" type="string" />

        <ResponseField name="_parent_id" type="string" />

        <ResponseField name="created_at" type="integer" />

        <ResponseField name="updated_at" type="integer" />

        <ResponseField name="user_id" type="integer" />

        <ResponseField name="permissions" type="object">
          <Expandable title="properties">
            <ResponseField name="read" type="object">
              <Expandable title="properties">
                <ResponseField name="access" type="string" />
              </Expandable>
            </ResponseField>

            <ResponseField name="update" type="object">
              <Expandable title="properties">
                <ResponseField name="access" type="string" />
              </Expandable>
            </ResponseField>

            <ResponseField name="delete" type="object">
              <Expandable title="properties">
                <ResponseField name="access" type="string" />
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Accordion>

  <Accordion title="400">
    An error response
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT \
  -H "Content-Type: application/json" \
  -H "QB-Token: 0bea0abd041b2431e5e1c2d0b06fab4414012bba" \
  -d '{
    "game_mode_name":"beta testing",
    "search_criteria":{
      "expert_mode":"false",
      "progress":{
        "gt":"0.2"
      }
    }
  }' \
  https://api.quickblox.com/data/ScoreTable/by_criteria.json
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "class_name": "ScoreTable",
    "skip": 0,
    "limit": 100,
    "total_found": 2,
    "items": [
      {
        "_id": "5d866b53a28f9a5ad51cb562",
        "_parent_id": null,
        "completed_levels": [
          1,
          2,
          3,
          4
        ],
        "created_at": 1569090387,
        "date": "2019-09-21T21:21:00Z",
        "expert_mode": false,
        "game_mode_name": "beta testing",
        "progress": 0.23,
        "score_value": 705,
        "updated_at": 1569177307,
        "user_avatar": null,
        "user_id": 96753878,
        "user_location": [
          11.13,
          45.52
        ],
        "permissions": {
          "read": {
            "access": "open"
          },
          "update": {
            "access": "owner"
          },
          "delete": {
            "access": "owner"
          }
        }
      },
      {
        "_id": "5d867291a0eb473ed96099c4",
        "_parent_id": null,
        "completed_levels": [
          1,
          2,
          3,
          4,
          5,
          6
        ],
        "created_at": 1569092241,
        "date": "2019-09-21T21:25:00Z",
        "expert_mode": false,
        "game_mode_name": "beta testing",
        "progress": 0.42,
        "score_value": 3021,
        "updated_at": 1569177307,
        "user_avatar": null,
        "user_id": 96753878,
        "user_location": null,
        "permissions": {
          "read": {
            "access": "open"
          },
          "update": {
            "access": "owner"
          },
          "delete": {
            "access": "owner"
          }
        }
      }
    ]
  }
  ```

  ```json 400 theme={null}
  {}
  ```
</ResponseExample>
