---
title: MongoDB Search Custom Script
slug: mongodb-search-custom-script
docTags: 
createdAt: 2026-03-23T19:44:10.204Z
---

## Overview

Mongo Custom Script Training allows the system to **fetch external data and store it directly in a Mongo database** for structured retrieval.

Instead of indexing text for semantic retrieval (RAG), this method stores **structured JSON objects** that can later be accessed through internal APIs.

This approach is useful when:

- Data needs **exact retrieval instead of semantic search**
- The application requires **structured database storage**
- Information needs to be accessed through **internal Mongo APIs**

Instead of returning page\_content for indexing, the script returns structured JSON using the **data\_to\_save** field.

The system stores this data directly inside the platform's **Mongo database**.

# Example Structure

The custom script must return JSON in the following format:

:::BlockQuote
\{
&#x20; "data\_to\_save": \{
&#x20;   "field\_1": "value",
&#x20;   "field\_2": "value",
&#x20;   "field\_3": "value"
&#x20; }
}
:::

# Supported Sources

Custom scripts can retrieve data from various external systems and convert it into **structured JSON** that can be indexed or stored by the platform.

Below are sample examples demonstrating how different data sources can be integrated using custom scripts.

Each example includes:

- **Script** — The Python code used to fetch and transform the data.

• **Response** — The JSON output returned by the script after execution.

This JSON output is processed by the system and used for **indexing or storing the data** depending on the use case.

:::Heading{depth="3" indent="1"}
[](https://docs.google.com/document/d/12nSS6U_vbvY7LPlNe-U2Rg3VO8f5rZmDWVROlGRuCNw/edit?usp=sharing)
:::

Fetch spreadsheet data from **Google Sheets**, convert each row into JSON, and store or index the records.

:::Heading{depth="3" indent="1"}
[](https://docs.google.com/document/d/12nSS6U_vbvY7LPlNe-U2Rg3VO8f5rZmDWVROlGRuCNw/edit?usp=sharing)&#x20;
:::

Retrieve structured data from **backend services or external APIs**, transform the response, and return it in JSON format.

Follow the steps below to complete the setup:

## 👇 Watch the Configuration Video

::embed[]{url="https://youtu.be/hcojujvT4kQ?si=1Ba-CUIg6qOuFFTR"}

👉 [Setup Guide](docId\:HWlylqfSLsUa5RPVMkmqF)



## 📚 Next Steps

Once the Mongo DB indexing status shows Ready to Search, configure the agent workflow so the AI can retrieve knowledge from the indexed website content.
➡️ Continue with [Mongo DB Path Setup](docId\:mGhUb2ljG7TRzpINTCZ2D)





