简体   繁体   中英

When connect firebase to node project it show db is not defined

When connect firebase to node project it show db is not defined.

在此处输入图像描述

Progress.js

const Progress = require("../models/progress");

//add new Progress

exports.addProgress = async (req, res) => {
 
  //constant variables for the attributes
  const {name, description, type, date,imgUrl} = req.body;
 
  //object
  const newProgress= new Progress({
    //initializing properties
    name,     
    description, 
    type, 
    date,
    imgUrl
  
  })
 
  //saving the object to the db 
  newProgress.save().then(() => {
    res.status(200).json({ status: "New Progress Added" });
  }).catch((error) => {
    res.status(500).json({message:"Fail to Progress Item",error:error.message})
  })
}

model 在此处输入图像描述

I think you missed to initialize DB, Try This -

const firestore = require("firebase-admin");
const db = firestore.firestore();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM