0
votes

I watched the tutorial for NodeJS + Firestore but i'm stuck new 4:50 mark where i need to type in db.collection.

video: Getting Started with Cloud Firestore with Node.js - Firecast https://www.youtube.com/watch?v=Z87OZtIYC_0

Steps:

  1. create NodeJS project

  2. npm install firebase-admin

    const admin = require('firebase-admin');
    
    admin.initializeApp({
       credential: admin.credential.applicationDefault()
    });
    
    const db = admin.firestore();
    
    db.collection();

Error: "unresolved function or method collection()"

Firebase version: firebase-admin": "^5.13.1"

firestore()/db indeed does not have the collections method. what am i missing?

3
This may not be the cause of the error you are seeing, but collection() expects a string argument for the path to the collection.Bob Snyder
well, i can't even get that far since collections isn't even considered a method of admin.firestore()MrBrent

3 Answers

0
votes

i found that after adding this package, everything started working.

npm install --save @google-cloud/firestore

0
votes

What helped me is not to use ES2015 improts and just do require

const admin = require('firebase-admin');
0
votes

try below, see if it fix

npm install @google-cloud/[email protected] --save


import * as admin from 'firebase-admin'; //Firebase Admin SDK
import {CollectionReference, DocumentData, DocumentReference, QuerySnapshot} from '@google-cloud/firestore';

const db = <any> admin.firestore();
const docRef = <DocumentReference> db.collection('col').doc(docId);