mongodb有没有在字母表或字符之前对数字进行排序的方法?
例如:1、2、3、4-我使用了collation({locale: "en_US", numericOrdering: true})
及其输出-,1,2,3,4。
但我预计1,2,3,4,-
您正在寻找自定义排序。
你可以按照下面的来做
{
$project:{
"customFieldToBeCreatedForSorting":{
$cond:[
{ $isNumber : "$FieldContainsMixedTypeData" },
NumberLong(1111111111), //This can be customized by finding max in the previous stage
$FieldContainsMixedTypeData
]
}
}
},
{
//$sort pipeline goes here
}