# Using DMK JavaScript Scripts

DMK provides a `$DMK_HOME/js` folder where several scripts are located. Feel free to add yours.

* `collection_size.js`: List all collections on the instance, including size, storage size, document count, and average object size.
* `db_sz.js`: List all databases on the instance.
* `get_cfg.js`: Retrieve the configuration information from mongosh.
* `get_uri.js`: Retrieve the MongoDB URI.
* `rs_status.js`: Display the current status of the replica set if the instance is part of one.
* `server_info.js`: Retrieve general information about the instance.

#### Example

```bash
mongodb@vm00:/home/mongodb/ [mdb01] msp $DMK_HOME/js/collection_size.js
Database: admin
--------------------------------------
  Collection: system.version
    Size: 		 0.00 MB
    Storage Size: 	 0.02 MB
    Count: 		 1
    Avg Object Size: 	 0.06 KB

Database: config
--------------------------------------
  Collection: system.sessions
    Size: 		 0.00 MB
    Storage Size: 	 0.00 MB
    Count: 		 0
    Avg Object Size: 	 0.00 KB

Database: local
--------------------------------------
  Collection: startup_log
    Size: 		 0.00 MB
    Storage Size: 	 0.02 MB
    Count: 		 1
    Avg Object Size: 	 2.51 KB
```

```bash
mongodb@vm00:/home/mongodb/ [mdb01] msp $DMK_HOME/js/server_info.js

General
  MongoDB version : 8.0.16
  Environment   : rhel88:x86_64
  Config file     : /u01/app/mongodb/admin/mdb01/etc/mdb01.conf
Replicaset
  No replicaset defined

Active connections:
{
  current: 4,
  available: 815,
  totalCreated: 33,
  rejected: 0,
  active: 1,
  threaded: 4,
  exhaustIsMaster: Long('0'),
  exhaustHello: Long('0'),
  awaitingTopologyChanges: Long('0'),
  loadBalanced: Long('0')
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dbi-services.gitbook.io/dmk-mongodb/scripts-and-automation/dmk_javascript_scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
