Mongoose find not working

in this section on vid they seem to apply find on schema its not working for me

my code

const express = require('express')
const mongoose =require( 'mongoose')
const connection_url='mongodb+srv://Advx:Advitya@cluster0.ixnfv.mongodb.net/tinderdb?retryWrites=true&w=majority'
const app = express();
const port = process.env.PORT || 8001
//middleware


mongoose.connect(connection_url,{
    useNewUrlParser:true,
    useCreateIndex:true,
    useUnifiedTopology:true
})

const cardSchema = mongoose.Schema({
    name:String,
    imgUrl:String
})

//api endpoint

app.get('/',(req,res)=>{
    res.status(200).send("helooo")
})

app.listen(port,()=>console.log(`listening to port ${port}`))

app.post('/tinder/cards',(req,res)=>{
    
    const dbCard = req.body;
//db config
    cardSchema.create(dbCard,(err,data)=>{
        if(err){
            res.send(500).send(err)
        }
        else{
            res.status(201).send(data)
        }
    })
})

app.get('/tinder/cards',(req,res)=>{
 
cardSchema.find((err,data)=>{
        if(err){
            res.send(500).send(err)
        }
        else{
            res.status(200).send(data)
        }
    });
});

//listener

Check carefully the part in video where they create Card schema, you’re missing model creation.

1 Like