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;
    }





    希望写博是我人生坚持在做的事情之一。
  • 相关阅读:
    [bzoj1054][HAOI2008]移动玩具
    atal error C1083: 无法打开包括文件:“stdint.h”
    诛仙手游宝石和灌注性价比分析
    诛仙手游攻略
    商务沟通方法与技巧
    韩服LOL符文翻译
    如何关闭"QQ网购每日精选"信息提醒
    LOL 韩服下载地址
    [经验分享] YY客服联系方式
    广州打印社保明细-网上打印-社保局地址
  • 原文地址:https://www.cnblogs.com/beixiaoyi/p/14578073.html
Copyright © 2011-2022 走看看