I am trying to do a simple .find() using mongoose/nodejs with mongoDB. I have a document (with field "date": "09-20-2019") in my collection (show) but I cannot seem to find it programmatically.
I have tried using MongoDB compass (db viewer software) to perform a search for what I am looking for. I passed into the search box under my collection {date: "09-20-2019"} and I was able to find the document using their search functionality so I know it should be working. I have checked that the field "date" is coming across to back end node server as the correct format and value of "09-20-2019". I am using Node.js 10.15.1
--This is from my route.js file
router.get('/shows/:date', (req, res, next)=>{
//res.send('Retrieving the shows list');
console.log('back end date: ' + req.params.date);
Show.find({date: req.params.date}, function(err, result){
if (err)
{
res.json(err);
}
else {
console.log(result);
res.json(result);
}
})
});
--This is from my show.js (mongodb schema file)
const mongoose = require('mongoose');
const ShowSchema = mongoose.Schema({
name:{
type: String,
required: true
},
date:{
type: String,
required: true
},
venue:{
type: String,
required: true
},
createdDate:{
type: String,
required: true
}
});
const Show = module.exports = mongoose.model('Show', ShowSchema);
--This is from my service.ts file
getShow(date)
{
var headers = new Headers();
headers.append('Content-Type', 'application/json');
//date is in format MM/dd/yyyy (e.g. 09-20-2019)
return this.http.get<Show>('http://localhost:3000/api/shows/' + date);
}
--This is from my component
this.commentCardService.getShow(this._date).subscribe(data => {
console.log(data);
});
I am expecting the .find({}) operation to return with a single document from my mongoDB of the show with the date of '09-20-2019' which is the only document that is in that collection at the moment. More than one document will exist in the collection ultimately.