After successfully creating a collection and a document in a local running database using mongosh, I encountered an issue while trying to access it via mongoose. Despite querying all documents using a model that matches the collection I created, the document could not be found.
user.js:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/zenwheels', {useNewUrlParser:true,
useUnifiedTopology: true});
const userSchema = new mongoose.Schema({
username:{
type: String,
required: true
},
password:{
type: String,
required: true
}
});
module.exports = mongoose.model('user', userSchema);
admin.js, where I perform the unsuccessful query (only relevant excerpts shown):
const user = require('../models/user');
router.get('/gettest/', async (req, res) =>{
try{
const users = await user.find();
res.json(users);
}catch(err){
res.send(500);
}
})
View of the Database in Compass: https://i.sstatic.net/Flcyf.png
NOTE: Previous attempts included establishing the db connection in admin.js (not shown in my latest attempt mentioned above), but encountered the same issue. Even after referencing the mongoose documentation on document retrieval, the problem persists.
Any assistance would be greatly appreciated.