赞
踩
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑上面是mongo的数据格式↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
Aggregation agg = Aggregation.newAggregation( // 第一步:挑选所需的字段,类似select *,*所代表的字段内容 Aggregation.project("begin", "end", "userId", "distance"), // 第二步:sql where 语句筛选符合条件的记录 // Aggregation.match(Criteria.where("userId").is(map.get("userId"))), // 第三步:分组条件,设置分组字段 Aggregation.group("userId").sum("distance").as("distance"), // 第四部:排序(根据某字段排序 倒序) Aggregation.sort(Sort.Direction.DESC,"distance"), // 第五步:数量(分页) Aggregation.limit(Integer.parseInt(map.get("pagesCount"))), // 第刘步:重新挑选字段 Aggregation.project("userId","distance") ); AggregationResults<JSONObject> results = mongoTemplate.aggregate(agg, "collectionName", JSONObject.class); List<JSONObject> mappedResults = results.getMappedResults();
下面是MongoDB String => Int 的代码
// collectionName => 表名
// distance => 字段
db.collectionName.find({distance:{$exists:true}}).forEach(function(obj){
obj.distance =new NumberInt(obj.distance);
db.collectionName.save(obj);
});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。