Skip to content

Add support for setting DataAccessMode in firebase.json#10065

Merged
joehan merged 9 commits intomainfrom
jh-dataaccessmode
Mar 18, 2026
Merged

Add support for setting DataAccessMode in firebase.json#10065
joehan merged 9 commits intomainfrom
jh-dataaccessmode

Conversation

@joehan
Copy link
Member

@joehan joehan commented Mar 10, 2026

Description

Seems like we overlooked this in go/firestore-data-access-mode - without this, all Enterprise edition DBs created via deploy are in MongoDB mode.

In the future, we probably want to flip the default here to be native mode - however, that is a breaking change so we will need to wait for a major version.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the ability to specify the dataAccessMode for Firestore databases within the firebase.json configuration. This enhancement addresses a previous limitation where Enterprise edition databases created via deployment would default to MongoDB compatibility mode, providing users with explicit control to choose between FIRESTORE_NATIVE and MONGODB_COMPATIBLE modes during database creation.

Highlights

  • Firestore Data Access Mode Configuration: Enabled the configuration of dataAccessMode for Firestore databases directly within firebase.json.
  • Enterprise Edition Support: Implemented logic to apply FIRESTORE_NATIVE or MONGODB_COMPATIBLE modes during the creation of Enterprise Firestore databases.
  • Validation: Added validation to ensure that dataAccessMode can only be specified for Enterprise edition databases, preventing misconfiguration for Standard editions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • CHANGELOG.md
    • Add support for dataAccessMode in Firestore database creation. This allows choosing between FIRESTORE_NATIVE and MONGODB_COMPATIBLE for enterprise edition databases.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for specifying dataAccessMode for Firestore databases in firebase.json, which is a great addition for enterprise edition databases. My review focuses on ensuring this change doesn't introduce unintended breaking changes and improves code clarity.

I've identified a potential breaking change where the default dataAccessMode for enterprise databases is altered. I've suggested a modification to preserve the existing behavior, along with an additional test case to cover this scenario. I also have a minor suggestion to simplify some conditional logic.

Overall, the changes are well-structured and the addition of tests is much appreciated.

Comment on lines +138 to +140
firestoreDataAccessMode: firestoreDataAccessMode ?? types.DataAccessMode.ENABLED,
mongodbCompatibleDataAccessMode:
mongodbCompatibleDataAccessMode ?? types.DataAccessMode.DISABLED,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Based on the PR description, changing the default dataAccessMode for enterprise databases is a breaking change that should be deferred to a future major version. This implementation changes the default to FIRESTORE_NATIVE for all databases if dataAccessMode is not specified. To avoid this breaking change for enterprise databases, the default should be conditional on the database edition, preserving MONGODB_COMPATIBLE as the default for enterprise.

        firestoreDataAccessMode:
          firestoreDataAccessMode ??
          (edition === types.DatabaseEdition.ENTERPRISE
            ? types.DataAccessMode.DISABLED
            : types.DataAccessMode.ENABLED),
        mongodbCompatibleDataAccessMode:
          mongodbCompatibleDataAccessMode ??
          (edition === types.DatabaseEdition.ENTERPRISE
            ? types.DataAccessMode.ENABLED
            : types.DataAccessMode.DISABLED),


let firestoreDataAccessMode: types.DataAccessMode | undefined;
let mongodbCompatibleDataAccessMode: types.DataAccessMode | undefined;
if (firestoreCfg.dataAccessMode) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need two dataAccessMode (firestoreDataAccessMode and mongoDataAccessMode - consistent with API design). Firestore will add support for both modes in the future (interoperability).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we could simplify this into a single field dataAccessMode, and turn it into an array once we add interoperability - ie:

// Just Mongo
dataAccessMode: MONGODB_COMPATIBLE

// Just Native

dataAccessMode: FIRESTORE_NATIVE

// Interop mode
dataAccessMode: [ MONGODB_COMPATIBLE, FIRESTORE_NATIVE]

This seemed more ergonomic to me (especially before interop is available), but I don't feel too strongly about this tho, so happy to match the backend API design if you prefer

@joehan joehan requested a review from pl04351820 March 17, 2026 17:45
@joehan
Copy link
Member Author

joehan commented Mar 17, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for setting dataAccessMode when creating a Firestore database, which is a valuable addition. The implementation is correct and includes a comprehensive set of new tests. My feedback focuses on improving code conciseness and adhering to the repository's TypeScript style guide, especially in the new test file to establish good patterns.

@@ -0,0 +1,160 @@
import { expect } from "chai";
import * as sinon from "sinon";
import * as prepare from "./prepare";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To better align with the style guide which advises against using any as an escape hatch (line 38), consider changing this to a default import. This will allow you to call the function directly as prepare(...) in your tests, avoiding the need for (prepare.default as any) casting at multiple call sites (e.g., line 58, 84, 110).

Suggested change
import * as prepare from "./prepare";
import prepare from "./prepare";
References
  1. The style guide states: "Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards." (link)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to do this? Or does the tsconfig.json setup break things?

Comment on lines +41 to +51
const options = {
projectId,
config: {
path: (p: string) => p,
data: {
firestore: {
database: "test-db",
},
},
},
} as unknown as Options;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The style guide (line 38) advises against using unknown as an escape hatch. Casting with as unknown as Options can make tests brittle and hide type errors. For new test files, it's a good practice to establish a pattern of creating more robust mocks. Consider creating a test utility to generate mock Options objects, or at a minimum, define the mock object with Partial<Options> and then cast to Options to make the partial nature of the mock more explicit.

References
  1. The style guide states: "Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards." (link)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about this since this kind of removes type safety

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna leave this for now since it is a test - however, we do have a mockOptions function definite in src/emulator/controller.spec.ts that could be turned into a general utility. Making a note to do so in a follow up PR (since we'll use it in other places too)

Comment on lines +111 to +117
if (firestoreCfg.dataAccessMode === "FIRESTORE_NATIVE") {
firestoreDataAccessMode = types.DataAccessMode.ENABLED;
mongodbCompatibleDataAccessMode = types.DataAccessMode.DISABLED;
} else if (firestoreCfg.dataAccessMode === "MONGODB_COMPATIBLE") {
firestoreDataAccessMode = types.DataAccessMode.DISABLED;
mongodbCompatibleDataAccessMode = types.DataAccessMode.ENABLED;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if/else if block can be made more concise and less repetitive by using a boolean variable to determine the mode and then using ternary operators for the assignments. This improves readability and aligns with the style guide's preference for simpler branching logic.

    const isNative = firestoreCfg.dataAccessMode === "FIRESTORE_NATIVE";
    firestoreDataAccessMode = isNative ? types.DataAccessMode.ENABLED : types.DataAccessMode.DISABLED;
    mongodbCompatibleDataAccessMode = isNative ? types.DataAccessMode.DISABLED : types.DataAccessMode.ENABLED;
References
  1. The style guide encourages reducing nesting and considering helper functions to encapsulate branching. While not reducing nesting, this change simplifies the branching logic, which is in the spirit of the rule. (link)

Copy link
Contributor

@maneesht maneesht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though it might be worth looking at the gemini review's comments in a few places

@joehan joehan enabled auto-merge (squash) March 18, 2026 21:59
@joehan joehan disabled auto-merge March 18, 2026 22:10
@joehan joehan merged commit 17db147 into main Mar 18, 2026
47 checks passed
@joehan joehan deleted the jh-dataaccessmode branch March 18, 2026 22:10
andrewbrook pushed a commit that referenced this pull request Mar 25, 2026
* Add support for setting DataAccessMode in firebase.json

* Dont change defaults

* Regen schema;

* pr fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants