我正在從 mongo 資料庫中獲取日期并回傳 $first、$max、$min和$last,但是發生了一些非常不尋常的事情 -$min大于$max. 這是我的代碼:
let Lowestdate = await ETHMongo.aggregate([
{
$match: { createdAt: { $gte: new Date(last), $lte: new Date(NEW) } },
},
{
$group: {
_id: null,
minFee_doc: { $first: "$$ROOT" },
minFee: { $min: "$one" },
firstFee: { $first: "$one" },
lastFee: { $last: "$one" },
maxFee: { $max: "$one" },
},
},
]).then((result) => {});
有什么解決辦法嗎?

uj5u.com熱心網友回復:
看起來您的“數字”string在字串比較中保存為"99" > "1000000"。
幸運的是,您可以很容易地解決這個問題,只需使用$toInt將字串轉換為數字
{
$group: {
_id: null,
minFee_doc: { $first: "$$ROOT" },
minFee: { $min: {$toInt: "$one"} },
firstFee: { $first: "$one" },
lastFee: { $last: "$one" },
maxFee: { $max: {$toInt: "$one"} },
},
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/463199.html
