Method: projects.commit

Commits a transaction, optionally creating, deleting or modifying some entities.

HTTP request

POST https://datastore.googleapis.com/v1beta3/projects/{projectId}:commit

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
projectId

string

Required. The ID of the project against which to make the request.

Request body

The request body contains data with the following structure:

JSON representation
{
  "mode": enum (Mode),
  "mutations": [
    {
      object (Mutation)
    }
  ],

  // Union field transaction_selector can be only one of the following:
  "transaction": string
  // End of list of possible types for union field transaction_selector.
}
Fields
mode

enum (Mode)

The type of commit to perform. Defaults to TRANSACTIONAL.

mutations[]

object (Mutation)

The mutations to perform.

When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single projects.commit request:

  • insert followed by insert
  • update followed by insert
  • upsert followed by insert
  • delete followed by update

When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

Union field transaction_selector. Must be set when mode is TRANSACTIONAL. transaction_selector can be only one of the following:
transaction

string (bytes format)

The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to Datastore.BeginTransaction.

A base64-encoded string.

Response body

The response for Datastore.Commit.

If successful, the response body contains data with the following structure:

JSON representation
{
  "mutationResults": [
    {
      object (MutationResult)
    }
  ],
  "indexUpdates": integer,
  "commitTime": string
}
Fields
mutationResults[]

object (MutationResult)

The result of performing the mutations. The i-th mutation result corresponds to the i-th mutation in the request.

indexUpdates

integer

The number of index entries updated during the commit, or zero if none were updated.

commitTime

string (Timestamp format)

The transaction commit timestamp. Not set for non-transactional commits.

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".

Authorization scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/datastore
  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Authentication Overview.

Mode

The modes available for commits.

Enums
MODE_UNSPECIFIED Unspecified. This value must not be used.
TRANSACTIONAL Transactional: The mutations are either all applied, or none are applied. Learn about transactions here.
NON_TRANSACTIONAL Non-transactional: The mutations may not apply as all or none.

Mutation

A mutation to apply to an entity.

JSON representation
{

  // Union field operation can be only one of the following:
  "insert": {
    object (Entity)
  },
  "update": {
    object (Entity)
  },
  "upsert": {
    object (Entity)
  },
  "delete": {
    object (Key)
  }
  // End of list of possible types for union field operation.

  // Union field conflict_detection_strategy can be only one of the following:
  "baseVersion": string,
  "updateTime": string
  // End of list of possible types for union field conflict_detection_strategy.
}
Fields

Union field operation. The mutation operation.

For insert, update, and upsert: - The entity's key must not be reserved/read-only. - No property in the entity may have a reserved name, not even a property in an entity in a value. - No value in the entity may have meaning 18, not even a value in an entity in another value. operation can be only one of the following:

insert

object (Entity)

The entity to insert. The entity must not already exist. The entity key's final path element may be incomplete.

update

object (Entity)

The entity to update. The entity must already exist. Must have a complete key path.

upsert

object (Entity)

The entity to upsert. The entity may or may not already exist. The entity key's final path element may be incomplete.

delete

object (Key)

The key of the entity to delete. The entity may or may not already exist. Must have a complete key path and must not be reserved/read-only.

Union field conflict_detection_strategy. When set, the server will detect whether or not this mutation conflicts with the current version of the entity on the server. Conflicting mutations are not applied, and are marked as such in MutationResult. conflict_detection_strategy can be only one of the following:
baseVersion

string (int64 format)

The version of the entity that this mutation is being applied to. If this does not match the current version on the server, the mutation conflicts.

updateTime

string (Timestamp format)

The update time of the entity that this mutation is being applied to. If this does not match the current update time on the server, the mutation conflicts.

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".

MutationResult

The result of applying a mutation.

JSON representation
{
  "key": {
    object (Key)
  },
  "version": string,
  "createTime": string,
  "updateTime": string,
  "conflictDetected": boolean
}
Fields
key

object (Key)

The automatically allocated key. Set only when the mutation allocated a key.

version

string (int64 format)

The version of the entity on the server after processing the mutation. If the mutation doesn't change anything on the server, then the version will be the version of the current entity or, if no entity is present, a version that is strictly greater than the version of any previous entity and less than the version of any possible future entity.

createTime

string (Timestamp format)

The create time of the entity. This field will not be set after a 'delete'.

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".

updateTime

string (Timestamp format)

The update time of the entity on the server after processing the mutation. If the mutation doesn't change anything on the server, then the timestamp will be the update timestamp of the current entity. This field will not be set after a 'delete'.

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".

conflictDetected

boolean

Whether a conflict was detected for this mutation. Always false when a conflict detection strategy field is not set in the mutation.