Ive been working on this app for about a month. A couple days ago my laptop died. Luckily I had saved alot of my work in Github but it wasnt completely up to date. Sucks but realistically just have to redo a day of work.I clone it and start it up and the Node backend was not working anymore even though I hadn't really touched it prior to the crash which is very confusing to me. It connects to my mongo database, but when I send queries in postman all I get back are empty arrays in postman. Here are some examples of the code.User Schema:const mongoose = require('mongoose');const UserSchema = mongoose.Schema({name: {type: String,required: true,min: 6,max: 30},email: {type: String,required: true,min: 6},password: {type: String,required: true,min: 6,max: 1024},date: {type: Date,default: Date.now}});const UserModel = mongoose.model('Users', UserSchema, 'Users');module.exports = UserModel;User Route:router.get('/', async (req, res) => {try {const user = await User.find();res.json(user);} catch(err) {res.json({message: err});}});usually this route would just get back all the users but like I said it just returns an empty array. I know there is a user in the collection and that it used to work. So from what I am gathering it is connecting to the database correctly, processing queries but for some reason it is not returning anything like the collection is empty.The name of my mongo collection is "Users". I am really really confused. I had mainly been working this prior to the crash on the frontend of my app, so I don't think there is so small piece of code lost in the mix. Prior to my crash everything worked great using Mongoose. ANY help would be greatly appreciated as I am losing my goddamn mind.
Submitted August 13, 2020 at 04:11PM by Raskputin
No comments:
Post a Comment