Firestore CollectionReference and DocumentReference types are lacking essential methods like .add(), .set(), .update(), etc

I am currently utilizing Firestore alongside React and Typescript. My goal is to fetch data from Firestore and update it. Despite finding numerous examples online with syntax involving methods, my IDE does not recognize these methods for the types involved.

As of now, I can successfully retrieve data from Firestore using functions like the following:

import { getFirestore, collection, doc, updateDoc } from 'firebase/firestore';

const firestore = getFirestore(config);

function App() {
  const collRef = collection(firestore, 'collection');
  const docRef = doc(firestore, 'collection/id');
  updateDoc(docRef, { test: 1234 }).then(x => console.log(x));
}

However, I have come across examples that utilize method chaining in the following manner:

firebase.firestore().collection('collection').doc('id').set({ test: 1234 });

Despite this, my IDE indicates that none of the types used in this chain possess these methods. Even the official documentation mentions that Reference types should include methods like .get(), .set(), and .update(), yet they are absent.

Although this seems straightforward, I must be overlooking a fundamental element. What could I be missing?

Answer №1

When it comes to the chaining method you mentioned, it's actually part of the older namespaced syntax. The newer Modular SDK (version 9.0.0 and above) has shifted to a more functional syntax, similar to what you have in your initial code snippet.

If you still want to use the older syntax, you can do so by switching to the compat version through these import changes:

import firebase from "firebase/compat/app"
import "firebase/compat/auth"
// import "firebase/compat/[SERVICE]"

However, we recommend updating your code to the new syntax in order to take advantage of tree shaking benefits. Be sure to check out the documentation for more details.

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

When form.setValues() is called, asynchronous validation is triggered repeatedly

In my Angular 5 application, I am utilizing the reactive forms approach. Within an Angular Material dialog, I have a form that is used for both data entry and editing. The constructor in my code looks like this: constructor(public formBuilder: FormBuilde ...

What is the process for generating a custom Firebase Authentication token in Node.js without using a service account JSON file?

I am looking to generate a custom token without relying on a service account json file. I have attempted the following configuration options: https://firebase.google.com/docs/auth/admin/create-custom-tokens#using_a_service_account_id https://firebase.goog ...

Error: Angular 6 - The 'map' operator is not available on an observable type

After updating to Angular 6, I encountered this error. While I found documentation on using .pipe(), I'm unsure how to implement it when there are multiple .map() functions as shown below. Your assistance would be greatly appreciated... import {In ...

Is it safe to use subjects in Angular like this, or are there potential security concerns?

When I find myself needing to use a variable in multiple components that can change over time, I typically store that variable in a service and encapsulate the value in a Subject. This allows every component to receive updates when next is called on the Su ...

Is the URL incorrect if fetching from Firestore URL results in a 404 error?

My current project involves fetching data from my Firestore Database using Next.js. However, I keep encountering an error in the console that reads GET (FirestoreDatabaseURL) 404 (not found). Interestingly, when I attempt to fetch data from other JSON dat ...

Finding a way to detect the mouse leaving two elements simultaneously in Angular4

Are you looking for the Angular4 equivalent of a particular jQuery functionality? Do you need to add multiple elements dynamically and are experiencing issues with the settimeout function in Angular4? Any thoughts on how to solve this? http://jsfiddle.net ...

Guide to implementing filtering based on selected checkboxes using data retrieved from an API

Is there a way to filter dealers based on the selected rating checkboxes? For example, if a user selects one star, only dealers with one star should be displayed. If a user selects two stars, dealers with both two and one stars should be shown. I am usin ...

Creating a relationship of dependence between functions in TypeScript: A guide

Apologies for the unclear title, I'm struggling to articulate my question effectively. Currently, I am attempting to create a method that can parse an object from an XML file. The XML structure (translated to JavaScript using xml-js) appears as follow ...

Exploring the differences between importing all utilities as a whole using `import * as util from "./util"` and importing a specific function only with `import {someFunction

When comparing the two options of importing from a module, which is better: import * as util from "./Util" or import {someFunction} from "./Util"? ...

What is the best way to assign ngModel to dynamically inserted input rows in Angular 4+ (specifically in a mat-table)?

Just a quick question - how can I add ngModel to dynamically added new input rows? I have a Mat table with multiple rows and an "add element" method that adds a new row every time a button is clicked. This way, I want to bind the user-entered values and se ...

What is the significance of secondary import in Firebase integration?

What is the reason behind having to import the same module twice when using Firebase? import { firestore, initializeApp } from 'firebase'; import 'firebase/firestore'; I am curious about why this scenario might occur in other node/js ...

retrieve the name or path of the route currently being accessed

Here is the navigation bar code snippet: <nav class="menu"> <a routerLink="textArea" class="menu-item">text-area</a> <a routerLink="dropdown" class="menu-item">dropdown</a& ...

Synchronizing data on the same web page across different browsers with Angular 8

I have developed an Angular application where I am fetching data using Angular HttpClient to consume a REST API. The received data consists of values that need to be displayed on a form page. When I make edits to the data and click save, the changes are sa ...

Here is a helpful guide on using the replace() function in JavaScript to swap out specific words within a text that match

My task involves manipulating the following text: const a: string = 'I like orange, blue, black, pink, rose, yellow, white, black'; Along with this string: const b: string =['black', 'yellow']; The objective is to replace ...

TypeScript asserts that the Function is not callable

There seems to be an issue with TypeScript not recognizing that a function of type Function is not callable. type Constructable = { new(...args: any[]): any } function isClass(func: any) { return ( typeof func === 'function' && ...

Sorting in an Angular mat table can be customized to consider two properties within a single

Trying to implement a table with MatSort, I've encountered an issue where every column sorts except for the third one: <ng-container matColumnDef="nbreEnregistrementTotal"> <th mat-header-cell *matHeaderCellDef mat-sort-header ...

Differentiating between model types and parameters in Prisma can greatly enhance your understanding of

Consider the following scenario: const modifyData = async(data, settings) => { await data.update(settings) } In this case, the data refers to any data source, and the settings consist of objects like where and options for updating the data. How can ...

Filter out items from an array in JSON that are not included in a separate array, utilizing TypeScript

Is there a way to remove objects from a JSON array that are not included in another array? let originalArray = [{ id: 1, NoOfEmp: 12, Wages:1000, TotalSI: 21, Salary:3000 }, { id: 2, NoOfEmp: 13, Wages:2000, TotalSI: 22, Salary:4000 ...

What is the most efficient way to post data to the most recently added resource/record in a database?

I need to update specific data in an existing record within the database using a POST method. Currently, every time I make a POST request, it creates a new record instead of updating the existing one. What is the most straightforward approach to achieve th ...

remove unnecessary parameters from a JavaScript object using curly braces

My query pertains to an object response below result.joblist = { "collection_job_status_list": [ { "application_context": { "application_id": "a4", "context_id": "c4" }, "creation_time": "15699018476102", "pro ...