• mongodb操作


    mongodb 的分页查询:

       public  List<NoticeSentRecordDto> select(NoticeSelectInfo noticeSelectInfo){
            Query query = new Query().with(new Sort(Sort.Direction.DESC, "createTime"));
            if (noticeSelectInfo.getCurrPage() != null && noticeSelectInfo.getPageSize() != null) {
                query.skip((noticeSelectInfo.getCurrPage()-1)*noticeSelectInfo.getPageSize())
                        .limit(noticeSelectInfo.getPageSize());
            }
            query.addCriteria(Criteria.where("isDeleted").is(0));
            if(!StringUtils.isEmpty(noticeSelectInfo.getType())){
                query.addCriteria(Criteria.where("type").is(noticeSelectInfo.getType()));
            }
            return template.find(query, NoticeSentRecordDto.class);
        }

    查询个数:

    template.count(query,NoticeSentRecordDto.class);

    根据id修改一条记录,并返回:
     public  NoticeSentRecordDto selectOne(NoticeSelectInfo noticeSelectInfo){
            Query query = new Query();
            query.addCriteria(Criteria.where("_id").is(noticeSelectInfo.getId()));
            Update update = new Update().set("isRead", true);
            template.updateFirst(query, update, NoticeSentRecordDto.class);
            return template.findOne(query, NoticeSentRecordDto.class);
        }
    

      

    设置mongobd 表保留的文档数:

           MongoDB有两种集合能实现比较类似的功能。
    一种是TTL(Time To Live)集合,mongod会自动删除过期的文档。
    http://docs.mongodb.org/manual/tutorial/expire-data/
    另一种是capped集合,该集合是一个固定大小的集合,当该集合存满数据时,mongod会自动通过覆盖最旧的文档来存放新的文档。
    http://docs.mongodb.org/manual/core/capped-collections/

    创建固定集合coll_testcapped,大小限制为1024个字节,文档数量限制为100。

    db.createCollection("coll_testcapped2",{capped:true,size:1024,max:100});
    https://www.cnblogs.com/xxcn/p/10183104.html
  • 相关阅读:
    错因集锦
    组合数学12
    硬币购物
    考试套路整理
    考前模板整理
    我的友链
    P4127 [AHOI2009]同类分布
    P1836 数页码_NOI导刊2011提高(04)
    P4124 [CQOI2016]手机号码
    数位DP小结
  • 原文地址:https://www.cnblogs.com/z360519549/p/11218704.html
Copyright © 2020-2023  润新知