Answer the question
In order to leave comments, you need to log in
How to properly search through an array of objects in mongoose?
There are documents like this:
{
"_id" : -1340306864,
"name" : "123",
"prices" : [
{
"name" : "",
"price" : 123231
}
]
}
{
"_id" : -1341439031,
"name" : "123",
"prices" : [
{
"name" : "123",
"price" : 1.123
},
{
"name" : "321",
"price" : 0.1
}
]
}
Product.find({name : {$regex : ".*"+filters.name+".*"}, "prices.price": {$gte : filters.price.min|| 0, $lte: filters.price.max || 9999999}}, {description: false}, (err, data) => {
if(err) return callback(err, null);
return callback(null, data);
}).limit(productsInPage).skip(filters.skipNumber);
filters.price.min
and filters.price.max
are equal null
, everything works fine, otherwise, when at least one variable is not equal, it null
displays an empty array. filters.price.min
and filters.price.max
100% number. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question