Expand description
§Firebase Firestore module
This module ports core pieces of the Firestore SDK to Rust so applications can discover collections and create, update, retrieve and delete documents.
It provides functionality to interact with Firestore, including retrieving and querying documents, working with collections, and managing real-time updates.
It includes error handling, configuration options, and integration with Firebase apps.
§Features
- Connect to Firestore emulator
- Get Firestore instance for a Firebase app
- Register Firestore component
- Manage collections and documents
- Build and execute queries
- Comprehensive error handling
§References to the Firebase JS SDK - firestore module
- QuickStart: https://firebase.google.com/docs/firestore/quickstart
- API: https://firebase.google.com/docs/reference/js/firestore.md#firestore_package
- Github Repo - Module: https://github.com/firebase/firebase-js-sdk/tree/main/packages/firestore
- Github Repo - API: https://github.com/firebase/firebase-js-sdk/tree/main/packages/firebase/firestore
§Development status as of 14th October 2025
- Core functionalities: Mostly implemented (see the module’s README.md for details)
- Tests: 31 tests (passed)
- Documentation: Most public functions are documented
- Examples: None provided
DISCLAIMER: This is not an official Firebase product, nor it is guaranteed that it has no bugs or that it will work as intended.
§Example
use firebase_rs_sdk::app::api::initialize_app;
use firebase_rs_sdk::app::{FirebaseAppSettings, FirebaseOptions};
use firebase_rs_sdk::app_check::api::{custom_provider, initialize_app_check, token_with_ttl};
use firebase_rs_sdk::app_check::{AppCheckOptions, FirebaseAppCheckInternal};
use firebase_rs_sdk::auth::api::auth_for_app;
use firebase_rs_sdk::firestore::*;
use std::collections::BTreeMap;
use std::time::Duration;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: replace with your project configuration
let options = FirebaseOptions {
project_id: Some("your-project".into()),
// add other Firebase options as needed
..Default::default()
};
let app = initialize_app(options, Some(FirebaseAppSettings::default()))?;
let auth = auth_for_app(app.clone())?;
// Optional: wire App Check tokens into Firestore.
let app_check_provider = custom_provider(|| token_with_ttl("fake-token", Duration::from_secs(60)));
let app_check = initialize_app_check(Some(app.clone()), AppCheckOptions::new(app_check_provider))?;
let app_check_internal = FirebaseAppCheckInternal::new(app_check);
let firestore = get_firestore(Some(app.clone()))?;
let client = FirestoreClient::with_http_datastore_authenticated(
firebase_rs_sdk::firestore::api::Firestore::from_arc(firestore.clone()),
auth.token_provider(),
Some(app_check_internal.token_provider()),
)?;
let mut ada = BTreeMap::new();
ada.insert("first".into(), FirestoreValue::from_string("Ada"));
ada.insert("last".into(), FirestoreValue::from_string("Lovelace"));
ada.insert("born".into(), FirestoreValue::from_integer(1815));
let ada_snapshot = client.add_doc("users", ada)?;
println!("Document written with ID: {}", ada_snapshot.id());
let mut alan = BTreeMap::new();
alan.insert("first".into(), FirestoreValue::from_string("Alan"));
alan.insert("middle".into(), FirestoreValue::from_string("Mathison"));
alan.insert("last".into(), FirestoreValue::from_string("Turing"));
alan.insert("born".into(), FirestoreValue::from_integer(1912));
let alan_snapshot = client.add_doc("users", alan)?;
println!("Document written with ID: {}", alan_snapshot.id());
Ok(())
}If App Check is not enabled for your app, pass None as the third argument to
with_http_datastore_authenticated.
Using Converters:
use firebase_rs_sdk::app::*;
use firebase_rs_sdk::firestore::*;
use std::collections::BTreeMap;
#[derive(Clone)]
struct MyUser {
name: String,
}
#[derive(Clone)]
struct UserConverter;
impl FirestoreDataConverter for UserConverter {
type Model = MyUser;
fn to_map(
&self,
value: &Self::Model,
) -> FirestoreResult<BTreeMap<String, FirestoreValue>> {
// Encode your model into Firestore fields.
todo!()
}
fn from_map(&self, value: &MapValue) -> FirestoreResult<Self::Model> {
// Decode Firestore fields into your model.
todo!()
}
}
fn example_with_converter(firestore: &Firestore, client: &FirestoreClient) -> FirestoreResult<Option<MyUser>> {
let users = firestore.collection("typed-users")?.with_converter(UserConverter);
let doc = users.doc(Some("ada"))?;
client.set_doc_with_converter(&doc, MyUser { name: "Ada".to_string() }, None)?;
let typed_snapshot = client.get_doc_with_converter(&doc)?;
let user: Option<MyUser> = typed_snapshot.data()?;
Ok(user)
}Modules§
Structs§
- Array
Value - Bytes
Value - Collection
Reference - Connection
- Connection
Builder - Converted
Collection Reference - Converted
Document Reference - Converted
Query - Database
Id - Document
Key - Document
Reference - Document
Snapshot - Snapshot of a document’s contents.
- Field
Path - Firestore
- Firestore
Client - Firestore
Error - Firestore
Value - GeoPoint
- Http
Datastore - Http
Datastore Builder - InMemory
Datastore - Json
Proto Serializer - MapValue
- Noop
Token Provider - Passthrough
Converter - Default converter that leaves Firestore maps unchanged (raw JSON-style data).
- Query
- Query
Definition - Query
Snapshot - Request
Context - Resource
Path - Retry
Settings - SetOptions
- Options that configure the behaviour of
set_docwrites. - Snapshot
Metadata - Metadata about the state of a document snapshot.
- Timestamp
- Typed
Document Snapshot - Document snapshot carrying a converter for typed access.
- Typed
Query Snapshot
Enums§
Constants§
Traits§
- Datastore
- Firestore
Data Converter - Trait describing how to convert between user models and Firestore maps.
- Token
Provider
Functions§
- get_
firestore - Resolves (or lazily instantiates) the Firestore service for the provided app.
- map_
http_ error - register_
firestore_ component