ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Deployments
    • Cloud
    • Server
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
    • Supported Driver Versions
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Install
Search Ask AI
ScyllaDB Docs ScyllaDB Node.js Driver Statements Batch Statements

Batch Statements¶

It’s common for applications to require atomic batching of multiple INSERT, UPDATE, or DELETE statements, even in different partitions or column families. The driver allows you to execute multiple statements atomically without the need to concatenate multiple queries.

Note

Batches containing statements that target different partitions will no longer be correctly token- and shard-aware, which will hurt performance. Batches should not normally be used to boost performance in ScyllaDB. Batches’ goal is enabling atomicity, not increased efficiency. If you want to execute multiple statements efficiently and you do not care about atomicity of the operation, we would recommend using executeConcurrent endpoint.

The method batch() accepts the list of queries as first parameter. Each query can be either just a statement string, or { query, params } object:

const query1 = 'INSERT INTO user_profiles (email) VALUES (\'example@example.com\`)';
const query2 = 'UPDATE user_profiles SET email = ? WHERE key = ?';
const query3 = 'INSERT INTO user_track (key, text, date) VALUES (?, ?, ?)';
const queries = [
  query1,
  { query: query2, params: [emailAddress, 'hendrix'] },
  { query: query3, params: ['hendrix', 'Changed email', new Date()] }
];
// Promise-based call
client.batch(queries, { prepare: true })
  .then(function() {
    // All queries have been executed successfully
  })
  .catch(function(err) {
    // None of the changes have been applied
  });

Or using the callback-based invocation

client.batch(queries, { prepare: true }, function (err) {
   // All queries have been executed successfully
   // Or none of the changes have been applied, check err
});

By preparing your statements, you will get the best performance and your JavaScript parameters correctly mapped to Cassandra types. The driver will prepare each statement once on each host and execute the batch every time with the different parameters provided.

Note

When an unprepared statement contains bind markers (?), the driver silently prepares the statement before execution. This is especially important in batches: for each statement with a non-empty list of values, the driver sends a prepare request sequentially, and results are not cached between client.batch() calls.

Avoid using unprepared batches unless all statements take no bind markers.

Note that batches are not suitable for bulk loading, there are dedicated tools for that. Batches allow you to group related updates in a single request, so keep the batch size small (in the order of tens). Refer to CQL documentation for information about correct and incorrect use of batches.

Was this page helpful?

PREVIOUS
Unprepared Statements
NEXT
Parameterized queries
  • Create an issue
  • Edit this page
ScyllaDB Node.js Driver
Search Ask AI
  • v0.6.1
    • main
    • v0.6.1
  • Getting Started
  • Statements
    • Executing CQL Statements - Best Practices
    • Unprepared Statements
    • Batch Statements
    • Parameterized queries
  • Fetching Large Result Sets
  • Logging
  • Policies
    • Load Balancing
    • Retry Policies
  • Authentication
  • Shutdown
  • Migration Guide
  • API Reference
    • Modules
      • auth
        • AuthProvider
        • Authenticator
        • PlainTextAuthProvider
      • concurrent
      • datastax
        • graph
        • search
      • errors
        • ArgumentError
        • AuthenticationError
        • BusyConnectionError
        • DriverInternalError
        • NoHostAvailableError
        • NotSupportedError
        • OperationTimedOutError
        • ResponseError
      • geometry
      • mapping
        • DefaultTableMappings
        • Mapper
        • ModelBatchItem
        • ModelMapper
        • Result
        • UnderscoreCqlToCamelCaseMappings
        • TableMappings
      • metadata
        • Aggregate
        • ClientState
        • ColumnMetadata
        • Index
        • KeyspaceMetadata
        • MaterializedView
        • Metadata
        • SchemaFunction
        • Strategy
        • TableMetadata
        • UdtField
        • UserDefinedType
      • metrics
        • DefaultMetrics
        • ClientMetrics
      • policies
        • addressResolution
          • AddressTranslator
          • EC2MultiRegionTranslator
          • MappingAddressTranslator
        • loadBalancing
          • AllowListPolicy
          • DCAwareRoundRobinPolicy
          • DefaultLoadBalancingPolicy
          • LegacyDefaultLoadBalancingPolicy
          • LoadBalancingConfig
          • LoadBalancingPolicy
          • RoundRobinPolicy
          • TokenAwarePolicy
        • reconnection
          • ConstantReconnectionPolicy
          • ExponentialReconnectionPolicy
          • ReconnectionPolicy
        • retry
          • FallthroughRetryPolicy
          • RetryPolicy
        • speculativeExecution
          • ConstantSpeculativeExecutionPolicy
          • NoSpeculativeExecutionPolicy
          • SpeculativeExecutionPolicy
        • timestampGeneration
          • MonotonicTimestampGenerator
          • TimestampGenerator
      • tracker
        • RequestLogger
        • RequestTracker
      • types
        • Duration
        • Integer
        • LocalDate
        • Long
        • ResultSet
        • ResultStream
        • Row
        • TimeUuid
        • Vector
    • Classes
      • AddressResolver
      • ByteOrderedToken
      • Client
      • DateRange
      • DateRangeBound
      • DseGssapiAuthProvider
      • DsePlainTextAuthProvider
      • Edge
      • Element
      • Encoder
      • EncoderMembers
      • ExecutionOptions
      • FrameReader
      • GraphResultSet
      • HashSet
      • Host
      • HostMap
      • LineString
      • Murmur3Token
      • Path
      • Point
      • Polygon
      • Property
      • RandomToken
      • SslOptions
      • Token
      • TokenRange
      • Vertex
      • VertexProperty
    • Interfaces
    • Events
    • Global Functions and Constants
Docs Tutorials University Contact Us About Us
© 2026 ScyllaDB | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 20 Jun 2026.
Powered by Sphinx 9.1.0 & ScyllaDB Theme 1.9.2