I'm new to Node JS Develop. I have developed a specific REST service with Express and Mongo DB. Now I need to develop a rest service that when I pass some letter get an array of items that have these letters. I suppose that I could develop a GET Rest service using like operator. I have tried with this code but is wrong:
router.get('/tire/autocomplete/:size', VerifyToken, function(req,res){
var size=req.params.size;
TechInfo.find({ Size: new RegExp(size, 'i') }).toArray(err, techinfos) => {
if (err) {
console.log(err);
return res.status(400).send({ status: 'ko', data: {msg: err.message }});
console.log(err);
}
res.status(200).send({status: 'ok', data: {msg: 'Size tires available', tires :techinfos}});
});
});
and this my model Schema
var TechInfoSchema = new Schema({
"ID_code" :{type: Number, required: true},
"inches" : {type: Number, required: true},
"Brand" : {type: String, required: true},
"Size" : {type: String, required: true},
"type" : {type: String, required: true}
},{
collection: 'techInfo'
});
var TechInfo = db.model('TechInfo',TechInfoSchema)
module.exports = TechInfo;
When i call my rest service using postman i recieve this error
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /api/v1.0/equipment/tires/autocoplete</pre>
</body>
There is some exaple that i can see about rest service to do this? Thanks