I want to get the maximum and minimum value from the database from a products table. But it is giving unexpected results which is not even logical and correct. I am not able to understand what's wrong with the query. I am using MongoDb. I have also checked the link laravel query php how to get max value within a range, i think the queries are correct. What may be wrong. The queries are:
echo "Max Value ".$max_scores_table = DB::table('products')->where('status', 'enabled')->max('product_data.15');
echo "Min Value ".$min_scores_table= DB::table('products')->where('status', 'enabled')->min('product_data.15');
And it is returning me this:
Max Value 99
Min Value 100
But the "Maximum" query returns "99" and the "Minimum" returns "100" ( Yes this is what it is giving, i have not typed it wrong) from the database. Even there are less values than 99 and greater value than 100. But it does not return those.
My Collection structure is as:
{
"_id": "574d6814ab8ff4110a75ee58",
"product_data": {
"15": "2000",
"16": "2000",
},
"status": "enabled",
}
{
"_id": "574d6814ab8ff4110a75ee59",
"product_data": {
"15": "99",
"16": "2000",
},
"status": "enabled",
}
{
"_id": "574d6814ab8ff4110a75ee60",
"product_data": {
"15": "100",
"16": "2000",
},
"status": "enabled",
}
There are also other fields in the collection than these, I've removed them to shorten the length. Can any one help, What's wrong with the query.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire