MongoDB 排序数字字符串

阅读 103

2022-04-25

  • Java 的 BigDecimal 转换到 MongoDB 时会变成 String
  • Spring Data 排序:
    Sort sort = Sort.by(Sort.Direction.DESC, "pay_money");
    query.with(sort)
      // String to Number sort
      .collation(Collation.parse("en_US").numericOrdering(true)); 
    
  • JS Shell 排序:
    db.t_instance_order.find({}, {instance_type: 1, pay_money: 1})
      .sort({instance_type: 1, pay_money: -1})
      .collation({locale: "en_US", numericOrdering: true})
      .limit(10);
    

精彩评论(0)

0 0 举报