At the moment, my express API has the following functioning code:
router.get('/Find', function(req, res, next){
Dog.findOne({
'Date_Time_Competed': req.query.Competed
}).then(function(dog){
res.send({
'Breed': dog.breed,
'Age': dog.ageInYears,
'Owner': dog.owner
})
}).catch(next);
});
This code queries a MongoDB database to retrieve information on breed, ageInYears, and owner, returning them in JSON format under the categories Breed, Age, and Owner.
Now, I am looking to use a .find() call to retrieve multiple entries, but I am facing difficulty in changing the field names when dealing with multiple entries.
Below is my current attempt, which is functional, but I am struggling to modify the field names. (Please note: There are additional fields in the database for each entry that I do not intend to use, which is why I am not specifying certain fields).
router.get('/Find', function(req, res, next){
Dog.find({
'Date_Time_Competed': req.query.Competed
}, 'breed ageInYears owner')
.then(function(dog){
res.send(dog);
}).catch(next);
});
Any insights or suggestions on how to proceed?