Advanced Features

This section outlines advanced capabilities of the Oracle Backend with Firebase APIs database service that go beyond basic document operations. These features enable developers to model complex data relationships, perform cross-collection queries, and enforce fine-grained access control using security rules.

Join Collection

Join collections allow clients to define and query across multiple relational tables configured in the project. These joins are created and managed through the Oracle Backend with Firebase APIs Console and are exposed as logical collections that can be queried like any other document collection.

Join Collection Setup and Prerequisites

A client can create a join query using the Console. Each join can further be used as a collection.

Prerequisites

How to Set Up

Collection Group Queries

A collection group allows you to query across all subcollections with the same name, regardless of where they exist in your document hierarchy. It’s different from a normal collection query, which only looks within a specific path. This is useful for querying deeply nested or distributed data structures.

Setup

Example 20-1 Rule for a Collection Group Named recipes:

match /.*/recipes {
  allow read: if <expression>;
}

You can filter documents across all subcollections named recipes and query by field values or document identifiers.

Collection Group Setup and Prerequisites

Prerequisites

How to Set Up

Standalone Duality View

A standalone duality view is an Oracle JSON relational duality view created in the project owner schema. It represents a relational hierarchy as one nested JSON document collection.

It differs from the Console’s Relational-to-Collection Mapping. The Console mapping creates project-managed collections for the individual tables in a hierarchy. A standalone duality view defines the document shape directly and is accessed through the SDK duality-view API.

A standalone view is not automatically registered as a regular Oracle Backend with Firebase APIs collection. An application accesses the view with the SDK’s duality-view collection API. See Managing Database Using CLI for the resource paths supported by the CLI.

Create a Standalone Duality View

The root JSON object has two identifiers with different roles:

The employees array below is embedded in each department document. employeeNumber exposes the employee primary key for applications that need to identify an employee. For example, a JavaScript application creates the view reference with dualityViewCollection(db, 'department_dv'); document operations use the root department document’s OID. The embedded employee array is part of that root document, so the SDK has no employee-level document reference to resolve.

CREATE TABLE dept (
  deptno NUMBER(2) CONSTRAINT pk_dept PRIMARY KEY,
  dname  VARCHAR2(14),
  loc    VARCHAR2(13)
);

CREATE TABLE emp (
  empno    NUMBER(4) CONSTRAINT pk_emp PRIMARY KEY,
  ename    VARCHAR2(10),
  job      VARCHAR2(9),
  mgr      NUMBER(4),
  hiredate DATE,
  sal      NUMBER(7,2),
  comm     NUMBER(7,2),
  deptno   NUMBER(2) CONSTRAINT fk_deptno REFERENCES dept
);

CREATE OR REPLACE JSON RELATIONAL DUALITY VIEW department_dv AS
SELECT JSON {
  '_id'            : d.deptno,
  'OID'            : SYS_MAKE_OID_FROM_PK(d.deptno),
  'departmentName' : d.dname,
  'location'       : d.loc,
  'employees'      : [
    SELECT JSON {
      'employeeNumber' : e.empno,
      'employeeName'   : e.ename,
      'job'            : e.job,
      'salary'         : e.sal
    }
    FROM emp e WITH INSERT UPDATE DELETE
    WHERE d.deptno = e.deptno
  ]
}
FROM dept d WITH INSERT UPDATE DELETE;

Security Rule

Publish a security rule for each operation that the application needs. _docId is the Oracle Backend with Firebase APIs document-path placeholder; it is separate from the JSON _id field.

match /department_dv/_docId {
  allow read: if request.auth != null &&
              resource.data.departmentName == 'SALES';
}

The standalone duality-view API supports add, update, read, and delete operations. setDoc() is not supported for a duality view.

Snapshot Reads

Snapshot reads allow clients to retrieve the state of a document or collection at a specific point in time. This is useful for:

Snapshot reads are supported by the underlying ORDS infrastructure and return complete document data for each read operation. The number of rows returned is determined by the document size, and pagination can be applied using limit clauses.

Snapshot Reads Setup and Prerequisites

Prerequisites

How to Use

Managing Database Using CLI

Prerequisite

Ensure that the setup of the CLI for Oracle Backend with Firebase APIs is complete.

See Also: Configure the CLI for detailed steps on how to set up the CLI for Oracle Backend with Firebase APIs

Note: The Oracle Backend with Firebase APIs CLI operates on project-managed collections and their published collection paths. A standalone duality view is accessed with the SDK’s duality-view collection API. For an unregistered standalone view, a collection-only command such as fusabase database query /department_dv reports an invalid document or collection reference.