Having trouble accessing specific results using Firestore's multiple orderBy (composite index) feature

I am facing an issue with a query that I run on various data types. Recently, one of the collections stopped returning results after I included orderBy clauses.

getEntitiesOfType(entityType: EntityType): Observable<StructuralEntity[]> {
    const collection = this.findCollection(entityType);

    const entities$ = this.afs
      .collection(collection, (ref) =>
        ref.orderBy('disabled').orderBy('title').orderBy('id') // The problem lies here
      )
      .snapshotChanges()
      .pipe(
        map((docs) =>
          docs.map((dca) => {
            const data = dca.payload.doc.data() as StructuralEntity;
            return {
              id: dca.payload.doc.id,
              title: data.title,
              name: data.name,
              type: data.type,
              icon: data.icon,
              model: data.model,
              context: data.context,
              disabled: data.disabled,
            } as StructuralEntity;
          })
        )
      );

    return entities$;
  }

The specific collection that stopped displaying results does not contain fields like disabled or title, which I recently added for ordering purposes. To troubleshoot, I even updated the index to include field id, but it still doesn't return any results.

I am puzzled as to why Firestore is not returning results based on this index. Can anyone offer insights into this?

disabled title id
undefined undefined "1"
undefined undefined "2"

Answer №1

Firestore ensures that only documents with values for the indexed fields are included in an index.

In case a document lacks a value for the inactive field, it will not appear in the composite index and therefore cannot be retrieved by a query utilizing that index.

To receive such documents in your query results, you must assign a default value to the new field in those documents.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for configuring Visual Studio Code to utilize path mappings for handling automatic imports

In order to streamline my project and avoid messy paths, I am implementing absolute paths that will allow for consistent imports regardless of the file's location in the project tree. For this purpose, I made adjustments to the tsconfig.json: "paths ...

Can the lib property in tsconfig.json override the target property?

Just starting out with Typescript, I have a query regarding the lib and target properties. Below is my tsconfig.json file: { "compilerOptions": { "target": "es5", "outDir": "./dist", "rootDir": "./src", "noEmitOnError": true, } } //index.ts consol ...

Exploring the creation of an Angular service that utilizes HttpClient for making GET requests, with a focus on the different

I've been diving into Angular lately and I'm facing some challenges with handling get requests. If you're interested, you can check out my code on Angular Stackblitz import { HttpClient} from '@angular/common/http'; import { Inject ...

Query the Firebase database in Angular2 to locate the latitude and longitude values that are nearest to the user's current coordinates

I am working with a database table named locations, which contains a list of places along with their corresponding lat/long coordinates. Additionally, I am utilizing geolocation to retrieve the user's current lat/long. My goal is to identify the loc ...

Tips for retrieving additional values from a chosen variable in Angular 10

Here is an array I have: export const Glcode = [ { id: 1, Type: 'Asset', Name: 'Cash at Head Office', code: '10018' }, { id: 2, Type: 'Asset', Name: 'POS ACCOUNT ', code: '10432' }, { ...

React / NextJS: Repeating Audiowave Component

I am currently developing a chat application in NextJS that includes text-to-speech functionality. To visualize the audio playback waveform, I have integrated a third-party library called wavesurfer.js Though the audio implementation is functioning proper ...

Navigate in Angular to the server but add token headers using an interceptor

I need to incorporate authenticated file serving from the backend into my Angular routing: { path: 'files/:id/:name', pathMatch: 'full', ??? } My HTTP interceptor is already set up to include token headers in other requests. What I wan ...

What are the steps to incorporate a 3D scene into a React website?

Can I get some advice on how to create a React web application using TypeScript? I want to be able to click a button and have it show a new page with a scene of a town. What is the best way to achieve this in my React project? I've heard about using R ...

Compilation issues in node-modules arise following the Vue package and i18next updates

Recently, I decided to upgrade from the i18n package to the newer version called i18next in my project. However, this update led to numerous errors popping up during compilation. Fortunately, by adding 'skipLibCheck' to the compiler options in th ...

Sharing slices of data among feature modules in NgRx allows for improved scalability and organization

I'm a newcomer to the world of NgRx and I find myself with some inquiries regarding the proper way to organize the state within a Store. Currently, we are in the process of developing an internal CRM system using Angular to manage client information. ...

Guide to creating a function and exporting it to a component in react with the help of typescript

I have a ParentComponent where I need to integrate a function from a separate file and incorporate it into the ParentComponent. The structure of the ParentComponent is as follows: function ParentComponent() { const count = 5; // this value usually co ...

React: Content has not been refreshed

MarketEvent.tsx module is a centralized controller: import * as React from 'react'; import EventList from './EventList'; import FullReduce from './FullReduce'; import './MarketEvent.less' export default class Mark ...

Creating an overloaded callable interface using TypeScript

The thread on implementing a callable interface provides some helpful information, but it doesn't fully address my specific query. interface lol { (a: number): (b: number) => string // (a: string): (b: string) => string // overloaded wi ...

Angular Service Singleton Utilized in Components

I have a structural question regarding my Angular application. I am following the widely-used core, shared, and feature modules structure, similar to the one found here. In my core module, I have a singleton notification service defined, but I use a custom ...

Slice an interactive div

I am currently working on setting up a horizontal sliding div for a menu. The layout consists of a left DIV that remains visible at all times, and a sliding DIV that appears horizontally when the menu is activated. My HTML code looks like this. <div id ...

Is there a missing .fillGeometry in the Figma plugin VectorNode?

The documentation for VectorNode mentions a property called fillGeometry. Contrary to this, TypeScript indicates that "property 'fillGeometry' does not exist on type 'VectorNode'". I seem to be missing something here. Can someone prov ...

Designing Angular2 Routing - Comparing Default Navigation Components to Login Implementation

I'm seeking guidance on the best approach in Angular2 for displaying a different view depending on whether the user is logged in or not. When a user is logged in, I want to display a navigation and menu bar component by default outside of the router- ...

What is the best method for releasing an NX library along with all its bundled dependencies?

This problem is quite common in GitHub's NX repository, but I have not been able to find a solution there. Within my workspace, I have two buildable libraries: ui/avatar and ui/icon, as well as a publishable library named bar The goal is to utilize ...

Error: Unable to access the 'DASH' property as it is undefined

Within my current project, I aim to showcase data related to cryptocurrencies. After making an API call, I successfully obtained a response. The specifications of my environment are as follows: Node: 8.9.5, Express: 4.16.4, Angular CLI: 7.3.6, Typescript ...

What are some effective ways to exclude multiple spec files in playwright?

Within my configuration, I have three distinct projects. One project is responsible for running tests for a specific account type using one login, while another project runs tests for a different login. Recently, I added a third project that needs to run t ...