Reputation: 316
Problem with a mongodb database using mongoose and express js, following a tutorial
The tutorial can be found here Tutortial Angular6 MEAN Stack
My server.js file content
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import Issue from './models/Issue';
const app = express();
const router = express.Router();
app.use(cors());
app.use(bodyParser.json());
mongoose.connect('mongodb://localhost:27017/issues', { useNewUrlParser: true });
const connection = mongoose.connection;
connection.once('open', () =>{
console.log("MongoDB connection established successfully");
});
router.route('/issues').get( (req, res) => {
Issue.find((err,issues) => {
if(err)
console.log(err);
else
res.json(issues);
});
});
My Issue.js file content
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
let Issue = new Schema ({
title: {
type: String
},
responsible: {
type: String
},
description: {
type: String
},
severity: {
type: String
},
status: {
type: String,
default: 'Open'
}
});
export default mongoose.model('Issue', Issue);
I also have my Issue collection with valid json data, but when I try to visit the url localhost:4000/issues, I get just an empty []
Also here are my permissions for data/db
ls -ail
total 12
656701 drwxrwxrwx 3 root root 4096 oct 15 18:56 .
2 drwxr-xr-x 25 root root 4096 oct 15 18:56 ..
658216 drwxrwxrwx 4 dan root 4096 oct 16 11:29 db
Can someone point me into the right direction? Thank you
Upvotes: 0
Views: 48
Reputation: 316
As @str mentioned the mongodb database is case sensitive so I made a mistake when i created my database in mongo.
I named my database Issues instead of issues so I had to use the following commands to solve it:
mongodump -d Issues -o mongodump/
use Issues
db.dropDatabase()
mongorestore -d issues mongodump/Issues
Thank you for the right pointers @str
Upvotes: 1