API Maker's MongoDB Deep Populate revolutionizes how developers manage complex data relationships across multiple database systems. Unlike MongoDB's native $lookup
or Mongoose's populate, which are limited to a single MongoDB instance, Deep Populate enables seamless querying across MongoDB and relational databases like MySQL, PostgreSQL, Oracle, SQL Server, MariaDB, TiDB, and Percona XtraDB in a single API call. This delivers unified, structured responses, making it ideal for dashboards, microservices, and enterprise applications.
Deep Populate extends MongoDB’s querying capabilities by fetching related data from different database engines, combining MongoDB’s flexible document structure with the structured reliability of SQL databases. This eliminates the need for complex backend orchestration, delivering nested data in a single, elegant API response.
A well-defined schema in API Maker organizes data and enhances Deep Populate efficiency by mapping relationships across databases without additional JSON wrappers.
products
Collection){
"collection": "products",
"fields": {
"_id": { "type": "objectId", "validations": { "required": true } },
"name": { "type": "string", "validations": { "required": true } },
"price": { "type": "number" },
"category": { "type": "string" },
"manufacturer_id": {
"type": "string",
"instance": "mysql",
"database": "inventory",
"collection": "manufacturers",
"column": "id"
}
}
}
The manufacturer_id
field embeds join configuration (instance
, database
, collection
, column
), enabling seamless cross-engine joins. API Maker automatically handles data type conversions (e.g., ObjectId
to integer) when querying via /api/schema/mongo/...
. See the official schema documentation for details.
Deep Populate supports various HTTP methods to fetch or update data across databases with MongoDB as the core.
Fetch products and their latest purchase records from a MySQL database:
GET /api/schema/mongo/shop/products?find={"status":"active"}&deep=[{
"s_key": "id",
"t_instance": "mysql",
"t_db": "store",
"t_col": "purchases",
"t_key": "product_id",
"isMultiple": true,
"select": "order_id,quantity,status",
"find": {"status": "completed"},
"limit": 5
}]
{
"name": "Smartwatch",
"category": "Wearables",
"purchases": [
{ "order_id": 321, "quantity": 2, "status": "completed" },
{ "order_id": 322, "quantity": 1, "status": "completed" }
]
}
Update products with nested purchase data:
PUT /api/schema/mongo/shop/products
Content-Type: application/json
{
"id": "abc123",
"name": "Smartwatch",
"deep": [
{
"s_key": "id",
"t_instance": "mysql",
"t_db": "store",
"t_col": "purchases",
"t_key": "product_id",
"find": { "status": "completed" },
"select": "order_id,status",
"isMultiple": true,
"limit": 3
}
]
}
{
"status": "updated",
"product": {
"id": "abc123",
"name": "Smartwatch",
"purchases": [
{ "order_id": 2001, "status": "completed" },
{ "order_id": 2002, "status": "completed" }
]
}
}
This same format can be used to fetch data from any database within API Maker with MongoDB as the main database.
Field | Description |
---|---|
s_key |
Source field (MongoDB) to match |
t_key |
Target field (related DB) to join to |
t_instance |
Target database instance |
t_db |
Target database name |
t_col |
Target table/collection |
find |
Filter for target data |
select |
Fields to include from target |
isMultiple |
Return multiple matches as an array |
limit |
Limit number of nested results |
See Core Fields Documentation.
Best for fetching one related entity per document.
GET /api/schema/mongo/shop/cities?find={"active":true}&deep=[
{
"s_key":"state_id",
"t_instance":"oracle",
"t_db":"geo",
"t_col":"states",
"t_key":"id",
"find":{"state_name":"GUJARAT"},
"isMultiple":false,
"select":"state_name,id",
"limit":5
}
]
[
{
"id": "64f1a8ef92",
"city_name": "AHMEDABAD",
"state_id": {
"id": 2101,
"state_name": "GUJARAT"
}
},
{
"id": "64f1a8ef93",
"city_name": "SURAT",
"state_id": {
"id": 2101,
"state_name": "GUJARAT"
}
}
]
cities
collection (MongoDB).deep
array links s_key
to t_key
.select
and limit
for faster responses.Ideal for hierarchical relationships (e.g., City → State → Country).
GET /api/schema/mongo/shop/cities?find={"active":true}&deep=[
{
"s_key":"state_id",
"t_instance":"oracle",
"t_db":"geo",
"t_col":"states",
"t_key":"id",
"select":"state_name,country_id",
"isMultiple":false,
"deep":[
{
"s_key":"country_id",
"t_instance":"mysql",
"t_db":"inventory",
"t_col":"countries",
"t_key":"id",
"select":"country_name",
"isMultiple":false
}
]
}
]
{
"id": 101,
"city_name": "AHMEDABAD",
"state_id": {
"id": 201,
"state_name": "GUJARAT",
"country_id": {
"id": 301,
"country_name": "INDIA"
}
}
}
deep
arrays define each join level.Level | Use When | Best For | Example Chain |
---|---|---|---|
Single-Level | One related record | Simple joins (e.g., State ↔ City) | cities → states |
Multi-Level | Nested data from multiple tables | Hierarchical views | cities → states → countries |
Deep Populate integrates MongoDB with:
Use these interchangeably in t_instance
.
Pairing MongoDB’s flexible document model with relational databases creates a powerful, scalable data ecosystem. MongoDB excels at dynamic, unstructured data, while relational databases ensure structured, transactional reliability.
This combination supports fast, adaptable applications for analytics, compliance, and more.
Capability | API Maker (Deep Populate) | Supabase | Firebase (Firestore) | Appwrite |
---|---|---|---|---|
Native MongoDB Support | Yes (first-class integration) | Not supported (PostgreSQL only) | Not supported (proprietary NoSQL) | Not supported (MariaDB; Mongo beta) |
Cross-Table/DB Population | Nested joins across MongoDB, MySQL, etc. | Only PostgreSQL joins | No joins; client-side merges | Limited relationship querying |
Multi-Level Nesting | Unlimited depth | One-level joins | Not supported | Up to three levels (unreliable) |
JSON-Defined Deep Queries | Yes, via { deep: [...] } |
Requires SQL or SDK calls | Requires manual fetch | Manual relationship mapping |
MongoDB ↔ SQL Joins | Fully supported | Not supported | Not supported | Not supported |
Caching & Performance | Automatic batching and optimization | PostgreSQL-only caching | Client-side caching | Basic caching; no relational cache |
s_key
and t_key
for faster joins.select
to reduce payload size.limit
and sort
for paginated nested data.Yes, via /api/gen/...
, but schemas improve performance and validation.
API Maker returns primary documents with null
or empty nested fields, with errors in the errors
field.
No strict limit, but 3–4 levels are optimal for performance and readability.
ObjectId
joins?Yes, API Maker automatically converts ObjectId
for SQL or other types if defined in the schema.
Yes, use limit
and skip
in the deep
object for pagination, especially with isMultiple: true
.
$lookup
?$lookup
is limited to MongoDB; Deep Populate works across SQL and NoSQL databases.
Yes, API Maker supports streaming for large isMultiple
datasets.
Yes, configurable at the API or collection level for better performance.
Use the API Maker Test Console, Postman, cURL, or JavaScript (fetch/axios).
MongoDB Deep Populate unifies your data stack, delivering documents and relational data in one efficient response.