So I am having trouble with queries using mongoose when using the where clause. They work when I filter on strings, but not with numbers.
Here is my model/schema:
// Schema
var Wheel = new mongoose.Schema({
name: String,
method: String,
size: Number,
width: Number,
weight: Number
});
// Model
var WheelModel = mongoose.model('Wheel', Wheel);
This query works:
var query = WheelModel.find();
query.where('method').equals('Cast/Spun');
query.limit(10);
query.exec(function (err, wheels) {
// wheel objects are returned
});
This is an example of a wheel object inside the array 'wheels'
{
"_id": "523de98b263add11a8d4fc4a",
"name": "AME Circlar RS",
"weight": 18.1,
"width": 7,
"method": "Cast/Spun",
"size": 15
}
This query below returns [], and does so for if I filter by size, width, and weight, and for any numbers
var query = WheelModel.find();
query.where('size').equals(15);
query.limit(10);
query.exec(function (err, wheels) {
if (!err) {
return res.send(wheels);
} else {
return console.log(err);
}
});
I have also tried
query.where('size', 15);
query.where('size', '15');
var query = WheelModel.find({ size: 15});
If I go:
query.where('size').ne(15);
Then I get results back, but they will include values where the size is 15. So I suspect I have some type issues, I just don't know what. Any help would be apprecicated!