node.js - Mongoose - Query returns nothing -
i have following query:
app.get('/matches/:latmin/:latmax/:lonmin/:lonmax', function(req, res){ var matches = city.find({ "latitude": {$gt : string(req.param.latmin), $lt : string(req.params.latmax) }, "longitude" : {$gt : string(req.param.lonmin), $lt : string(req.param.lonmax)} }); matches.exec(function(err, match){ if(err){ console.log(err); return res.send(err); } console.log(match); res.json(match); }); });
here schema:
var mongoose = require('mongoose'); var schema = mongoose.schema; module.exports = mongoose.model('city', new schema({ zip : {type : string, default: ''}, latitude : {type : string, default: ''}, longitude : {type: string, default: ''}, city : {type: string, default: ''}, state : {type: string, default: ''}, county : {type: string, default: ''} }), 'locations');
when run query in mongo shell, expected results sent. however, log in above quotes returns []. there wrong i'm doing here?
i don't know if want use req.param
or typo. anyway, req.param
deprecated , should use req.params
.
i have set scenario , queries working. replace var matches
in code following:
var matches = city.find({ "latitude": {$gt : string(req.params.latmin), $lt : string(req.params.latmax) }, "longitude" : {$gt : string(req.params.lonmin), $lt : string(req.params.lonmax)} });
Comments
Post a Comment