How to load data from MongoDb to Google Firestore

Learn how to use Airbyte to synchronize your MongoDb data into Google Firestore within minutes.

Trusted by data-driven companies

Building your pipeline or Using Airbyte

Airbyte is the only open source solution empowering data teams  to meet all their growing custom business demands in the new AI era.

Building in-house pipelines
Bespoke pipelines are:
  • Inconsistent and inaccurate data
  • Laborious and expensive
  • Brittle and inflexible
Furthermore, you will need to build and maintain Y x Z pipelines with Y sources and Z destinations to cover all your needs.
After Airbyte
Airbyte connections are:
  • Reliable and accurate
  • Extensible and scalable for all your needs
  • Deployed and governed your way
All your pipelines in minutes, however custom they are, thanks to Airbyte’s connector marketplace and AI Connector Builder.

Start syncing with Airbyte in 3 easy steps within 10 minutes

Set up a MongoDb connector in Airbyte

Connect to MongoDb or one of 400+ pre-built or 10,000+ custom connectors through simple account authentication.

Set up Google Firestore for your extracted MongoDb data

Select Google Firestore where you want to import data from your MongoDb source to. You can also choose other cloud data warehouses, databases, data lakes, vector databases, or any other supported Airbyte destinations.

Configure the MongoDb to Google Firestore in Airbyte

This includes selecting the data you want to extract - streams and columns -, the sync frequency, where in the destination you want that data to be loaded.

Take a virtual tour

Check out our interactive demo and our how-to videos to learn how you can sync data from any source to any destination.

Demo video of Airbyte Cloud

Demo video of AI Connector Builder

What sets Airbyte Apart

Modern GenAI Workflows

Streamline AI workflows with Airbyte: load unstructured data into vector stores like Pinecone, Weaviate, and Milvus. Supports RAG transformations with LangChain chunking and embeddings from OpenAI, Cohere, etc., all in one operation.

Move Large Volumes, Fast

Quickly get up and running with a 5-minute setup that supports both incremental and full refreshes, for databases of any size.

An Extensible Open-Source Standard

More than 1,000 developers contribute to Airbyte’s connectors, different interfaces (UI, API, Terraform Provider, Python Library), and integrations with the rest of the stack. Airbyte’s AI Connector Builder lets you edit or add new connectors in minutes.

Full Control & Security

Airbyte secures your data with cloud-hosted, self-hosted or hybrid deployment options. Single Sign-On (SSO) and Role-Based Access Control (RBAC) ensure only authorized users have access with the right permissions. Airbyte acts as a HIPAA conduit and supports compliance with CCPA, GDPR, and SOC2.

Fully Featured & Integrated

Airbyte automates schema evolution for seamless data flow, and utilizes efficient Change Data Capture (CDC) for real-time updates. Select only the columns you need, and leverage our dbt integration for powerful data transformations.

Enterprise Support with SLAs

Airbyte Self-Managed Enterprise comes with dedicated support and guaranteed service level agreements (SLAs), ensuring that your data movement infrastructure remains reliable and performant, and expert assistance is available when needed.

What our users say

Jean-Mathieu Saponaro
Data & Analytics Senior Eng Manager

"The intake layer of Datadog’s self-serve analytics platform is largely built on Airbyte.Airbyte’s ease of use and extensibility allowed any team in the company to push their data into the platform - without assistance from the data team!"

Learn more
Chase Zieman headshot
Chase Zieman
Chief Data Officer

“Airbyte helped us accelerate our progress by years, compared to our competitors. We don’t need to worry about connectors and focus on creating value for our users instead of building infrastructure. That’s priceless. The time and energy saved allows us to disrupt and grow faster.”

Learn more
Alexis Weill
Data Lead

“We chose Airbyte for its ease of use, its pricing scalability and its absence of vendor lock-in. Having a lean team makes them our top criteria.
The value of being able to scale and execute at a high level by maximizing resources is immense”

Learn more

How to Sync MongoDb to Google Firestore Manually

  1. Log in to your Google Cloud Console.
  2. Select or create a new project where you want your Firestore database to reside.
  3. Navigate to the Firestore service in the console and set it up in either Native or Datastore Mode, depending on your requirements.
  4. Go to the IAM & Admin page, then Service Accounts. Create a new service account with the necessary permissions (Firestore Data Editor) to interact with Firestore.
  5. Generate a new private key for the service account and download the JSON file. This file will be used to authenticate your application with Google Cloud.
  1. Connect to your MongoDB database using the MongoDB shell or a GUI tool like MongoDB Compass.
  2. Use MongoDB’s export tools (mongoexport) to export the collections you want to move to Firestore. For example:

mongoexport --db=mydatabase --collection=mycollection --out=mycollection.json

  1. Ensure the exported data is in a JSON format that can be easily read and written to Firestore.
  1. Create a new directory for your migration script.
  2. Initialize a new Node.js project by running npm init -y in your terminal.
  3. Install the required npm packages:

npm install firebase-admin mongodb

  1. Place your downloaded Firestore private key JSON file in the project directory.

Create a new file migrate.js in your project directory, and follow these steps:

  1. Initialize Firebase Admin SDK with your service account:

const admin = require('firebase-admin');

const serviceAccount = require('./path-to-your-service-account-file.json');

admin.initializeApp({

  credential: admin.credential.cert(serviceAccount)

});

const firestore = admin.firestore();

  1. Connect to your MongoDB database:

const { MongoClient } = require('mongodb');

const uri = "your-mongodb-connection-string";

const client = new MongoClient(uri);

async function connectMongoDB() {

  try {

    await client.connect();

    console.log("Connected to MongoDB");

  } catch (e) {

    console.error("Connection to MongoDB failed", e);

  }

}

  1. Read data from MongoDB and write it to Firestore:

async function migrateData() {

  try {

    const database = client.db("your-database-name");

    const collection = database.collection("your-collection-name");

    const cursor = collection.find({});

    while (await cursor.hasNext()) {

      const doc = await cursor.next();

      await firestore.collection("your-firestore-collection-name").doc(doc._id.toString()).set(doc);

      console.log(`Document ${doc._id} migrated to Firestore`);

    }

  } catch (e) {

    console.error("Data migration failed", e);

  } finally {

    await client.close();

  }

}

  1. Run the migration function:

async function main() {

  await connectMongoDB();

  await migrateData();

}

main().catch(console.error);

Run your script using Node.js:

node migrate.js

The script will connect to your MongoDB, read the data from the specified collection, and write each document to your Firestore collection.

After the script finishes running, verify that the data has been successfully transferred to Firestore:

  1. Go to the Firestore section of the Google Cloud Console.
  2. Navigate to the Data tab and browse the collections and documents to ensure your data is present and correct.

Remember to remove any sensitive data, such as the service account JSON file, from your working directory when you’re done to prevent unauthorized access.

Notes:

  • This guide assumes a basic understanding of JavaScript and Node.js.
  • The Firestore document IDs are set to the MongoDB document _id converted to a string. If your MongoDB _id field is not unique or if you prefer different IDs in Firestore, you’ll need to adjust the script accordingly.
  • This script does not handle complex data transformations or schema migrations. If your Firestore schema differs from MongoDB, you’ll need to modify the script to transform the data as needed.
  • Always test your migration script with a small subset of data before running it on your entire dataset to ensure it works as expected.

How to Sync MongoDb to Google Firestore Manually - Method 2:

FAQs

ETL, an acronym for Extract, Transform, Load, is a vital data integration process. It involves extracting data from diverse sources, transforming it into a usable format, and loading it into a database, data warehouse or data lake. This process enables meaningful data analysis, enhancing business intelligence.

MongoDB is a popular open-source NoSQL database that stores data in a flexible, document-based format. It is designed to handle large volumes of unstructured data and is highly scalable, making it a popular choice for modern web applications. MongoDB uses a JSON-like format to store data, which allows for easy integration with web applications and APIs. It also supports dynamic queries, indexing, and aggregation, making it a powerful tool for data analysis. MongoDB is widely used in industries such as finance, healthcare, and e-commerce, and is known for its ease of use and flexibility.

MongoDB gives access to a wide range of data types, including:

1. Documents: MongoDB stores data in the form of documents, which are similar to JSON objects. Each document contains a set of key-value pairs that represent the data.
2. Collections: A collection is a group of related documents that are stored together in MongoDB. Collections can be thought of as tables in a relational database.
3. Indexes: MongoDB supports various types of indexes, including single-field, compound, and geospatial indexes. Indexes are used to improve query performance.
4. GridFS: MongoDB's GridFS is a specification for storing and retrieving large files, such as images and videos, in MongoDB.
5. Aggregation: MongoDB's aggregation framework provides a way to perform complex data analysis operations, such as grouping, filtering, and sorting, on large datasets.
6. Transactions: MongoDB supports multi-document transactions, which allow multiple operations to be performed atomically.
7. Change streams: MongoDB's change streams provide a way to monitor changes to data in real-time, allowing applications to react to changes as they occur.

Overall, MongoDB provides access to a flexible and powerful data model that can handle a wide range of data types and use cases.

This can be done by building a data pipeline manually, usually a Python script (you can leverage a tool as Apache Airflow for this). This process can take more than a full week of development. Or it can be done in minutes on Airbyte in three easy steps: 
1. Set up MongoDB to Google Firestore as a source connector (using Auth, or usually an API key)
2. Choose a destination (more than 50 available destination databases, data warehouses or lakes) to sync data too and set it up as a destination connector
3. Define which data you want to transfer from MongoDB to Google Firestore and how frequently
You can choose to self-host the pipeline using Airbyte Open Source or have it managed for you with Airbyte Cloud. 

ELT, standing for Extract, Load, Transform, is a modern take on the traditional ETL data integration process. In ELT, data is first extracted from various sources, loaded directly into a data warehouse, and then transformed. This approach enhances data processing speed, analytical flexibility and autonomy.

ETL and ELT are critical data integration strategies with key differences. ETL (Extract, Transform, Load) transforms data before loading, ideal for structured data. In contrast, ELT (Extract, Load, Transform) loads data before transformation, perfect for processing large, diverse data sets in modern data warehouses. ELT is becoming the new standard as it offers a lot more flexibility and autonomy to data analysts.

What should you do next?

Hope you enjoyed the reading. Here are the 3 ways we can help you in your data journey:

flag icon
Easily address your data movement needs with Airbyte Cloud
Take the first step towards extensible data movement infrastructure that will give a ton of time back to your data team. 
Get started with Airbyte for free
high five icon
Talk to a data infrastructure expert
Get a free consultation with an Airbyte expert to significantly improve your data movement infrastructure. 
Talk to sales
stars sparkling
Improve your data infrastructure knowledge
Subscribe to our monthly newsletter and get the community’s new enlightening content along with Airbyte’s progress in their mission to solve data integration once and for all.
Subscribe to newsletter