Switch Operations to a Different Node


  • By default, when working with multiple nodes,
    all client requests will access the server node that is defined by the client configuration.
    (Learn more in: Load balancing client requests).

  • However, server maintenance operations can be executed on a specific node by using the forNode method.
    (An exception is thrown if that node is not available).

  • In this page:


Server maintenance operations - forNode

  • For reference, all server maintenance operations are listed here.

// Default node access can be defined on the store        
const documentStore = new DocumentStore(["serverUrl_1", "serverUrl_2", "..."], "DefaultDB");

// For example:
// With readBalanceBehavior set to: 'FastestNode':
// Client READ requests will address the fastest node
// Client WRITE requests will address the preferred node
documentStore.conventions.readBalanceBehavior = "FastestNode";
documentStore.initialize();

// Use 'forNode' to override the default node configuration 
// Get a server operation executor for a specific node
const serverOpExecutor = await documentStore.maintenance.server.forNode("C");

// The maintenance.server operation will be executed on the specified node 'C'
const dbNames = await serverOpExecutor.send(new GetDatabaseNamesOperation(0, 25));

Syntax:

await store.maintenance.server.forNode(nodeTag);
Parameters Type Description
nodeTag string The tag of the node to operate on
Return Value
Promise<ServerOperationExecutor> A promise that returns a new instance of Server Operation Executor
scoped to the requested node