Skip to main content

Admin JS Console

  • The Admin JS Console lets you run JavaScript code on the server or a specific database,
    with low-level access and context objects.

  • This page contains a partial list of available methods that can be executed using the console.

Do not use the console unless you are sure of what you're doing.
Incorrect usage may crash the server, corrupt data, or cause irreversible changes.


Admin JS Console view

NoSQL DB Server Debug - Admin JS Console

  1. Navigate to Manage Server > Admin JS Console.

  2. Script target
    Choose the target for the script:
    Select Server to run a script against the server,
    or choose a database from the dropdown to run the script in the context of that database.

  3. Script
    Write your JavaScript code in the editor:

    • If you selected the server as the target, use the server variable.
      This object in your script is a direct reference to the live C# RavenServer instance in the RavenDB backend.
      Any method you call on it will be executed on the actual server object.
    • If you selected a database as the target, use the database variable.
      This object in your script is a direct reference to the live C# DocumentDatabase instance in the RavenDB backend. Any method you call on it will be executed on the actual database object.
  4. Run
    Click the Run button to execute the script.

  5. Script results
    The output will be displayed in this results panel.

Context objects in scripts

  • In addition to the server and database objects, the Admin JS Console provides access to three context variables: serverCtx, databaseCtx, and clusterCtx.

  • If your script calls a method that requires one of these contexts, you can use the corresponding variable.
    They are created for you and disposed automatically after the script runs.

  • Before using a context,
    you must open a transaction on it using OpenReadTransaction() or OpenWriteTransaction().


Context Variables

VariableTypeScope
databaseCtxDocumentsOperationContextSpecific database
serverCtxTransactionOperationContextSingle RavenDB node
clusterCtxClusterOperationContextEntire cluster

Script examples

// Get number of documents in the selected database
databaseCtx.OpenReadTransaction();
return database.DocumentsStorage.GetNumberOfDocuments(databaseCtx);

// Get the current server node tag
clusterCtx.OpenReadTransaction();
return server.ServerStore.Engine.ReadNodeTag(clusterCtx);

// Get the name of a server-wide backup task by ID
serverCtx.OpenReadTransaction();
return server.ServerStore.Cluster.GetServerWideTaskNameByTaskId(serverCtx,
'server-wide/backup/configurations', 1);

Console methods

This is a partial list of methods that can be invoked on the server object from the Admin JS Console.


Methods under server.ServerStore.Engine

server.ServerStore.Engine.*

Methods

MethodParametersDescription
HardResetToPassive()Cluster Topology IDForce this server to leave its cluster and change state to passive. The server will not be able to perform ongoing tasks while it is in passive state.

This method takes a cluster topology ID. If null is passed, the node will retain its current cluster topology ID. If you want to later add this server to an existing cluster, its cluster topology ID needs to match that cluster's ID.
HardResetToNewCluster()Cluster node tagForce this server to leave its cluster and bootstrap a new cluster (in which it is the only node and is in state leader).

This method takes a node tag. If null is passed, the server's node tag will be A.
FoundAboutHigherTerm()long; stringSet the term number of this server to the first parameter — a number of type long. A cluster's term number is incremented each time an election occurs. If you pass a number greater than the current term, the server's term number will update, then propagate this value to the rest of the cluster.

Note: This does not trigger an election, the leader node remains leader.

If you pass a number smaller than the current term, the server and cluster retain their current term number — this can be used to break an election that doesn't end on its own, i.e. when the cluster is stuck in "voting in progress".

The second parameter is a string that will be printed to the log of the term update: it records the reason for the change in term. It can be set to null.

Variables

VariableTypeDescription
RequestSnapshotbooleanSet this value to true to make this server request the raft logs from the leader node of its cluster. This will allow the server to resynchronize.
In this article