routes

Namespace

routes

Description:
  • This module contains routes for administrative database operations.

Source:

Methods

(async, static) DELETE /admin/databases/:dbName/collections/:collectionName(req, res) → {void}

Description:
  • Deletes a collection in the specified database.

Source:
Examples
// Curl Example:
curl -X DELETE http://localhost:3000/admin/databases/my_database/collections/my_collection
// Response:
{
  "success": true,
  "message": "Collection deleted successfully"
}
Parameters:
Name Type Description
req Request

Express request object containing database and collection names as URL parameters.

res Response

Express response object.

Returns:

Sends a success or error response.

Type
void

(async, static) GET /admin/databases(req, res) → {void}

Description:
  • Retrieves a list of all available databases in the MongoDB instance.

Source:
Examples
// Curl Example:
curl -X GET http://localhost:3000/admin/databases
// Response:
{
  "databases": [
    { "name": "admin", "sizeOnDisk": 8192, "empty": false },
    { "name": "local", "sizeOnDisk": 4096, "empty": false }
  ]
}
Parameters:
Name Type Description
req Request

Express request object.

res Response

Express response object.

Returns:

Renders a list of databases or sends an error response.

Type
void

(async, static) GET /admin/databases/:dbName/collections(req, res) → {void}

Description:
  • Retrieves a list of collections in the specified database.

Source:
Examples
// Curl Example:
curl -X GET http://localhost:3000/admin/databases/my_database/collections
// Response:
{
  "collections": [
    { "name": "users" },
    { "name": "products" }
  ]
}
Parameters:
Name Type Description
req Request

Express request object containing the database name as a URL parameter.

res Response

Express response object.

Returns:

Renders a list of collections or sends an error response.

Type
void

(async, static) GET /admin/databases/:dbName/collections/:collectionName/newSchema(req, res) → {void}

Description:
  • Retrieves the schema for a collection in the specified database.

Source:
Examples
// Curl Example:
curl -X GET http://localhost:3000/admin/databases/my_database/collections/my_collection/newSchema
// Response:
{
  "dbName": "my_database",
  "collectionName": "my_collection",
  "schema": {
    "field1": "value1",
    "field2": "value2"
  }
}
Parameters:
Name Type Description
req Request

Express request object containing database and collection names as URL parameters.

res Response

Express response object.

Returns:

Renders the schema or sends an error response.

Type
void

(async, static) GET /admin/databases/:dbName/collections/:collectionName/schema(req, res) → {void}

Description:
  • Retrieves the schema for a specific collection in the specified database.

Source:
Examples
// Curl Example:
curl -X GET http://localhost:3000/admin/databases/my_database/collections/my_collection/schema
// Response:
{
  "dbName": "my_database",
  "collectionName": "my_collection",
  "schema": {
    "keys": {
      "booleans": { "isActive": true },
      "ownerNameKeys": ["owner1", "owner2"],
      "addressKeys": ["address1"]
    },
    "baseUrls": { "url1": "https://example.com" }
  }
}
Parameters:
Name Type Description
req Request

Express request object containing database and collection names as URL parameters.

res Response

Express response object.

Returns:

Renders the schema or sends an error response in case of failure.

Type
void

(async, static) POST /admin/databases(req, res) → {void}

Description:
  • Creates a new database by providing a name and initializing it with a default collection.

Source:
Examples
// Curl Example:
curl -X POST http://localhost:3000/admin/databases -H "Content-Type: application/json" -d '{"name": "test_db"}'
// Response:
{
  "success": true,
  "message": "Database created successfully",
  "name": "test_db"
}
Parameters:
Name Type Description
req Request

Express request object containing the database name in the body.

res Response

Express response object.

Returns:

Sends a success or error response.

Type
void

(async, static) POST /admin/databases/:dbName/collections(req, res) → {void}

Description:
  • Adds a new collection to the specified database.

Source:
Examples
// Curl Example:
curl -X POST http://localhost:3000/admin/databases/my_database/collections -H "Content-Type: application/json" -d '{"name": "my_collection"}'
// Response:
{
  "success": true,
  "message": "Collection created successfully",
  "redirectUrl": "/databases/my_database/collections/my_collection/newSchema"
}
Parameters:
Name Type Description
req Request

Express request object containing the database name as a URL parameter and the collection name in the body.

res Response

Express response object.

Returns:

Sends a success or error response.

Type
void

(async, static) POST /admin/databases/:dbName/collections/:collectionName/newSchema(req, res) → {void}

Description:
  • Updates or creates a schema for the specified MongoDB collection in the database. Ensures proper handling of keys, data types, and dependencies on the available_layers database.

Source:
Examples
// Curl Example:
curl -X POST http://localhost:3000/admin/databases/my_database/collections/my_collection/newSchema \
-H "Content-Type: application/json" \
-d '{
  "keys": {
    "booleans": { "isActive": "true", "isDeleted": "false" },
    "ownerNameKeys": ["ownerName1", "ownerName2"],
    "addressKeys": "addressKey1"
  },
  "baseUrls": {
    "key1": "https://example.com",
    "key2": "https://another.com"
  }
}'
// Response:
HTTP/1.1 302 Found
Location: /databases/my_database/collections/my_collection/schema
Parameters:
Name Type Description
req Request

Express request object containing database and collection names as URL parameters, and the schema update details in the body.

res Response

Express response object.

Returns:

Redirects to the schema page or renders an error response in case of failure.

Type
void

(async, static) POST /admin/databases/:dbName/collections/:collectionName/schema(req, res) → {void}

Description:
  • Updates or creates a schema for the specified collection in the given database. Handles various input validations, merges fields, and manages dependencies on the available_layers database.

Source:
Examples
// Curl Example:
curl -X POST http://localhost:3000/admin/databases/my_database/collections/my_collection/schema \
-H "Content-Type: application/json" \
-d '{
  "keys": {
    "booleans": { "isActive": "true", "isArchived": "false" },
    "ownerNameKeys": ["owner1", "owner2"],
    "addressKeys": "address1"
  },
  "baseUrls": {
    "key1": "https://example.com",
    "key2": "https://another.com"
  }
}'
// Response (Redirect):
HTTP/1.1 302 Found
Location: /databases/my_database/collections/my_collection/schema
Parameters:
Name Type Description
req Request

Express request object containing database and collection names as URL parameters and the schema update details in the body.

res Response

Express response object.

Returns:

Redirects to the schema page or renders an error response in case of failure.

Type
void

(async, static) PUT /admin/databases/:dbName/collections/:collectionName/schema(req, res) → {void}

Description:
  • Updates the schema for a specific collection in the specified database.

Source:
Examples
// Curl Example:
curl -X PUT http://localhost:3000/admin/databases/my_database/collections/my_collection/schema \
-H "Content-Type: application/json" \
-d '{
  "keys": {
    "booleans": { "isActive": true },
    "ownerNameKeys": ["owner1"],
    "addressKeys": ["address1"]
  },
  "baseUrls": { "url1": "https://example.com" }
}'
// Response:
{
  "message": "Schema updated successfully"
}
Parameters:
Name Type Description
req Request

Express request object containing database and collection names as URL parameters and the new schema in the body.

res Response

Express response object.

Returns:

Sends a success message or an error response in case of failure.

Type
void