WDI-SEA / project-4-issues

Open an issue to receive help on project 4 issues
0 stars 0 forks source link

Empty posts on MongoDB #10

Closed DG-98 closed 2 years ago

DG-98 commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

MERN

What's the problem you're trying to solve?

When using a post route in postman, the db entry ends up being empty for some reason

Post any code you think might be relevant (one fenced block per file)

  // set owner of new example to be current user
  // req.body.Video.owner = req.user.id
  List.create(req.body)
    // respond to succesful `create` with status 201 and JSON of new "example"
    .then((createdList) => {
      res.status(201).json({ createdList: createdList.toObject() })
    })
    // if an error occurs, pass it off to our error handler
    // the error handler needs the error message and the `res` object so that it
    // can send an error message back to the client
    .catch(next)
})

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

no error message just posts with no body

What is your best guess as to the source of the problem?

Honestly not sure, I've tried checking spelling and syntax but it made no difference

What things have you already tried to solve the problem?

tkolsrud commented 2 years ago

try console logging req.body to see if anything's hitting the server

DG-98 commented 2 years ago

this is what's returned image

tkolsrud commented 2 years ago

and nothing shows up in your database?

DG-98 commented 2 years ago

This is what the entries look like image

tkolsrud commented 2 years ago

It seems like since the req.body is already an object you're taking some extra steps?

DG-98 commented 2 years ago

I cut back on some stuff so it posts like this: image but it still shows up in the DB like the other pic I sent

tkolsrud commented 2 years ago

what's your schema look like?

DG-98 commented 2 years ago


const listSchema = new mongoose.Schema(
    {
        animeId: {
            type: Number,
            require: true,
        },
        title: {
            type: String,
            require: true,
        }
    }
)

const List = mongoose.model("List", listSchema)

module.exports = List 
tkolsrud commented 2 years ago

So i think that's your issue. AnimeID and title are nested inside of "List", and aren't getting assigned to their respective keys in the schema