Home > database >  updateDoc: Uncaught FirebaseError: Invalid document reference
updateDoc: Uncaught FirebaseError: Invalid document reference

Time:04-06

When updating a document in v9 of firebase/firestore I got an error and I've been following the official documentation and not sure what I'm doing wrong:

import { initializeApp } from "firebase/app";
import { getFirestore, updateDoc, doc} from 'firebase/firestore';
import firebaseConfig from '../utils/firestore';

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

function updateSeries(docID, name, desc) {

    const data = {
        name: name,
        desc: desc,
        lastUpdatedAt: Timestamp.now(),
    }

    const seriesDocRef = doc(db, "MY_COL", docID)


    return new Promise((resolve, reject) => {
        updateDoc(seriesDocRef, data).then(() => {
            resolve();
        }).catch((e) => {
            reject(e);
        })
    })
}

When I call this function I get this error:

errors.ts:94 Uncaught FirebaseError: Invalid document reference. Document references must have an even number of segments, but MY_COL has 1.

CodePudding user response:

If the values in passed into the doc function are undefined or falsy it can cause this error. Please check if the db and docID variables are defined in:

const seriesDocRef = doc(db, "MY_COL", docID)
  • Related