zoukankan      html  css  js  c++  java
  • mongo 操作数据库的方式

    1. jpa

    eg1

    public interface CouponInfoRepository extends MongoRepository<CouponInfo, String>{

    /**
    * 跟进优惠券类型ID查找卷码
    * @param couponId 优惠券类型ID
    * @return 列表
    */
    List<CouponInfo> findByCouponId(String couponId);
    }
    List<CouponInfo> couponInfos = couponInfoRepository.findByCouponId(couponId);


    2.spting data MongoTemplate

    eg1:

    Criteria criteria = new Criteria();
    criteria.and("couponState").is(EnumCouponState.PUBLISH);
    TypedAggregation typedAggregation = TypedAggregation.newAggregation(Coupon.class, Arrays.asList(
    TypedAggregation.match(criteria),
    TypedAggregation.group("brandName")));
    AggregationResults<Map> aggregationResults = mongoTemplate.aggregate(typedAggregation, Map.class);

    eg2:
    Original original = mongoTemplate.findById("600fe698fececf417c47acea", Original.class);
    @Getter
    @Setter
    @ToString(callSuper = true)
    @Document(collection = "original")
    @EqualsAndHashCode(callSuper = true)
    @CompoundIndexes({
    @CompoundIndex(name = "tenantId_1_updateTime_1", def = "{'tenantId':1, 'updateTime':1}", background = true),
    @CompoundIndex(name = "tenantId_1_originalId_1", def = "{'tenantId':1, 'originalId':1}", unique = true, background = true)
    })
    public class Original extends BaseClue {

    /** 活动ID */
    private String activityId;

    /** 原始线索业务ID */
    private String originalId;

    /** 归集结果 */
    private GroupResultEnum groupResult;

    /** 扩展标记 */
    private String mark;

    /** 询底价:试驾时间 */
    private Date driveTime;
    }





    希望写博是我人生坚持在做的事情之一。
  • 相关阅读:
    CSS之APP开发比较实用的CSS属性
    关于 js 中的 call 和 apply使用理解
    灵感一:搜索型APP,帮助读书爱好者,搜索某本书的关键字
    常用排序算法:基数排序
    常用排序算法:桶排序
    常用排序算法:计数排序
    常用排序算法:希尔排序
    常用排序算法:归并排序
    常用排序算法:堆排序
    常用排序算法:快速排序
  • 原文地址:https://www.cnblogs.com/beixiaoyi/p/14578073.html
Copyright © 2011-2022 走看看