Get Started with Firebase Realtime Database for C++ Stay organized with collections Save and categorize content based on your preferences.
The Firebase Realtime Database stores and synchronizes data using a NoSQL clouddatabase. Data is synchronized across all clients in realtime, and remainsavailable when your app goes offline.
Before You Begin
Before you can useFirebase Realtime Database,you need to:
Register your C++ project and configure it to use Firebase.
If your C++ project already uses Firebase, then it's already registered andconfigured for Firebase.
Add theFirebaseC++ SDK to your C++ project.
Note that adding Firebase to your C++ project involves tasks both in theFirebase console and in your open C++ project (for example, you downloadFirebase config files from the console, then move them into your C++ project).
Create a Database
Navigate to theRealtime Database section of theFirebase console.You'll be prompted to select an existing Firebase project.Follow the database creation workflow.
Select a starting mode for yourFirebase Security Rules:
- Test mode
Good for getting started with the mobile and web client libraries,but allows anyone to read and overwrite your data. After testing,makesure to review theUnderstand Firebase Realtime Database Rulessection.
- Note: If you create a database in Test mode and make no changes to thedefault world-readable and world-writeableRules within a trialperiod, you will be alerted by email, then your database rules willdeny all requests. Note the expiration date during theFirebase consolesetup flow.
To get started with the web, Apple, or Android SDK, select testmode.
- Locked mode
Denies all reads and writes from mobile and web clients.Your authenticated application servers can still access your database.
Choose a location for the database.
Depending on thelocation of the database, theURL for the new database will be in one of the following forms:
(fordatabases inDATABASE_NAME.firebaseio.comus-central1) (for databases in all other locations)DATABASE_NAME.REGION.firebasedatabase.app
ClickDone.
When you enableRealtime Database, it also enables the API in theCloud API Manager.
Create and Initialize firebase::App
Before you can access theRealtime Database, you'll need to create and initialize thefirebase::App.
Include the header file forfirebase::App:
#include"firebase/app.h"
Android
Create thefirebase::App, passing the JNI environment and ajobjectreference to the Java Activity as arguments:
app=::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"),jni_env,activity);
iOS+
Create thefirebase::App:
app=::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"));
Access the firebase::database::Database Class
Thefirebase::database::Databaseis the entry point for theFirebase Realtime Database C++ SDK.
::firebase::database::Database*database=::firebase::database::Database::GetInstance(app);
If you have chosen to use public access for your rules, you can proceed to thesections on saving and retrieving data.
Setting up Restricted Access
If you do not want to use public access you can addFirebase Authentication to yourapp to control access to the database.
Next Steps
Learn how tostructure data forRealtime Database.
Prepare to launch your app:
- Set upbudgetalertsfor your project in theGoogle Cloud console.
- Monitor theUsage and billingdashboard in theFirebase console to get an overall picture of your project'susage across multiple Firebase services.You can also visit theRealtime DatabaseUsagedashboard for moredetailed usage information.
- Review theFirebase launch checklist.
Known Issues
- On desktop platforms (Windows, Mac, Linux), theFirebaseC++ SDK usesREST to access your database. Because of this, you mustdeclare the indexes you usewith Query::OrderByChild() on desktop or your listeners will fail.
- The desktop workflow version ofRealtime Database does not support offline orpersistence.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.