Skip to main content

Accessing database driver

Get Actual Database Name

The getActualDbName method returns the database name used by Agnost. If you selected "Assign a unique name to this database in different versions of the application" when creating a database in Agnost Studio, Agnost assigns a unique database name. This method returns the actual database name used in your application.


Sometimes, the database methods provided by the Agnost server library might not be enough to implement your use case. In those cases, you need direct access to the database client (e.g., driver) and perform your database operations through the native client. In those instances, if you need to use the name of the database, especially if the database name is automatically generated by Agnost to minimize name conflicts, then this method will provide you the database name string.

const dbName = agnost.db("myDb").getActualDbName();
console.log("Actual Database Name:", dbName);

Get Client

The getClient method returns the database client that you can use to perform advanced database operations. A client instance for the following NPM modules will be returned based on the database type:


Please note that if you update the database schema for a database managed by Agnost using the native client, these changes will not be reflected in your Agnost application. It is recommended to use Agnost Studio to perform database schema changes.

const dbClient = agnost.db("myDb").getClient();