search travels by from.name and to.name

This commit is contained in:
arnaucode
2017-02-01 23:44:27 +01:00
parent a29558b80e
commit 983f9533a0
2 changed files with 3 additions and 3 deletions

View File

@@ -29,8 +29,8 @@ exports.searchByString = function (req, res) {
if (err) return res.send(500, err.message);
travelModel.find({
$or:[
{from: new RegExp(req.params.searchstring, "i")},
{to: new RegExp(req.params.searchstring, "i")},
{'from.name': new RegExp(req.params.searchstring, "i")},
{'to.name': new RegExp(req.params.searchstring, "i")},
{title: new RegExp(req.params.searchstring, "i")}
]
})//perquè retorni tots els objectes que continguin l'string sense necessitat de que sigui exactament la mateixa string

View File

@@ -19,7 +19,7 @@ var travelSchema = new Schema({
long: {type: Number},
name: { type: String, required: true }
},
date: { type: Date },
date: { type: Date, required: true },
periodic: { type: Boolean },
generateddate: { type: Date },
seats: { type: Number, required: true },