skip to Main Content

Building Registration api for student with using of Firebase, already initialize Firebase.

trying all the different methods and see all the answer on stack overflow but still got the error and double check my Firebase initialize error show in portman

const { error } = require('console');
const firebase = require('../db.js');
const Student = require('../models/student.js')
const firestore = require('../db.js');
const { collection, doc, setDoc, getDocs } = require("firebase/firestore");
// const firestore = firebase.firestore();


const addStudent = async (req, res, next) => {
    try {
        const data = req.body;
        // await firestore.collection('students').doc().set(data);
        // collection(firestore, "students" )
        // const q = query(collection(firestore, "students".doc().set(data)));

        const docRef = doc(collection(firestore, 'students'));
        await setDoc(docRef, data);
        console.log(q,"q is");
        res.send('Record saved successfuly');
    } catch (error) {
        res.status(400).send(error.message);
    }
}

2

Answers


  1. Chosen as BEST ANSWER

    As the commenters have pointed out, you're using the older API syntax while i am importing the v9 SDK.

    The message is about this line

    firestore.collection("Students").doc(studentid).collection("links") In the new modular syntax, that should be:

    collection(firestore, "Students", StudentUid, "links")


  2. It typically means that the Firestore instance has not been initialized correctly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search