apps/www/_blog/2025-03-20-migrating-mongodb-data-api-with-supabase.mdx
MongoDB announced that their Data API and HTTPS Endpoints will reach end-of-life by September 30, 2025. This has left many engineering teams evaluating alternatives. Supabase includes built-in support for REST APIs (via PostgREST), mirroring the core functionality previously provided by MongoDB's Data API.
MongoDB's Data API allowed developers to interact with their Atlas databases through straightforward RESTful endpoints, simplifying integration across frontend, backend, and serverless applications. With its removal, developers must pivot to alternative methods such as native MongoDB drivers combined with backend frameworks (Express, SpringBoot, FastAPI), or third-party solutions like RESTHeart, Hasura, or Neurelo.
This shift requires substantial refactoring for teams that rely on the simplified REST interface.
Supabase is an open-source MongoDB alternative and offers:
Most notably, Supabase automatically generates a RESTful API from your database schema, powered by PostgREST, itself a stable open-source project with a strong community. This feature accelerates development by eliminating boilerplate code for basic CRUD operations. Supabase provides a near drop-in replacement for MongoDB’s Data API. The Supabase Data API also supports GraphQL and a host of mobile and web application frameworks.
In the end, you can focus on migrating your data, expose your data using Supabase’s Data API, and seamlessly integrate with your client applications.
To migrate to Supabase, you will need to:
Export MongoDB documents using mongoexport:
mongoexport --uri="mongodb+srv://<username>:<password>@cluster.mongodb.net/<dbname>" \
--collection=users \
--jsonArray \
--out=users.json
Create a table in Supabase with a JSONB column to store raw Mongo documents:
create table mongo_users_raw (
id uuid primary key default gen_random_uuid(),
data jsonb not null
);
Then, ingest the exported JSON data into this Supabase table using this custom script:
import { createClient } from '@supabase/supabase-js'
import fs from 'fs'
const supabaseUrl = 'YOUR_SUPABASE_URL'
const supabaseKey = 'YOUR_SUPABASE_API_KEY'
const tableName = 'YOUR_TABLE_NAME'
const jsonFilePath = './filename.json'
const supabase = createClient(supabaseUrl, supabaseKey)
async function loadDocumentsToSupabase() {
try {
// Read JSON file
const rawData = fs.readFileSync(jsonFilePath)
const dataArray = JSON.parse(rawData).map((data) => ({ data }))
// Insert data into Supabase
const { error } = await supabase.from(tableName).insert(dataArray)
if (error) {
console.error('Error inserting data:', error)
return
}
console.log(`Successfully inserted ${dataArray.length} records into ${tableName}`)
} catch (error) {
console.error('Error in process:', error)
}
}
loadDocumentsToSupabase()
Once your data is imported as JSONB, leverage PostgreSQL’s powerful JSON functions to incrementally normalize and populate relational tables:
-- Example to normalize user data
INSERT INTO users (name, email)
SELECT
data->>'name' as name,
data->>'email' as email
FROM mongo_users_raw;
-- Example to normalize orders into a separate table
INSERT INTO orders (user_id, product, quantity)
SELECT
u.id,
orders->>'product',
(orders.value->>'quantity')::INTEGER
FROM mongo_users_raw m
JOIN users u ON (m.data->>'name') = u.name,
LATERAL jsonb_array_elements(m.data->'orders') AS order_data
Once your data has been structured into tables, Supabase automatically generates REST APIs for each table via PostgREST, allowing effortless querying from your application.
For example, if you have a users table, querying user information using Supabase’s JavaScript library would look like this:
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://<your-project>.supabase.co', '<your-api-key>')
// Fetch user named John along with their orders
const { data, error } = await supabase
.from('users')
.select(
`
id, name,
orders (product, quantity)
`
)
.eq('name', 'John')
if (error) {
console.error(error)
} else {
console.log(data)
}
Using the automatically generated Supabase REST APIs offers a clear migration path from MongoDB’s deprecated Data API.
Once your data is migrated, you can start to use Supabase to its fullest:
Supabase is an ideal replacement for MongoDB, especially considering the Data API deprecation. Supabase is built on Postgres, one of the world’s most powerful and scalable databases. In addition, Supabase’s Data API directly parallels MongoDB's Data API, offering a simplified transition path.
This blog post provides further detail on how to transition from MongoDB. If you’re encountering difficulty, feel free to reach out to us. We’d be happy to help.
With careful planning and methodical execution, engineering teams can navigate this migration confidently, leveraging Supabase as a trusted, long-term solution.