From 983f9533a0c9edf388f4ef42eca15ef97f38b40c Mon Sep 17 00:00:00 2001 From: arnaucode Date: Wed, 1 Feb 2017 23:44:27 +0100 Subject: [PATCH] search travels by from.name and to.name --- controllers/searchController.js | 4 ++-- models/travelModel.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/searchController.js b/controllers/searchController.js index 0f1dfb7..c59e4b8 100644 --- a/controllers/searchController.js +++ b/controllers/searchController.js @@ -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 diff --git a/models/travelModel.js b/models/travelModel.js index 57dc357..16140ca 100644 --- a/models/travelModel.js +++ b/models/travelModel.js @@ -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 },