zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    HTML编码规范(转)
    ASP.NET连接MySQL数据库方法(测试可行)
    Redis源码解析05: 压缩列表
    Redis源码解析04: 跳跃表
    Redis源码解析03: 字典的遍历
    Redis源码解析02: 字典
    Redis源码解析01: 简单动态字符串SDS
    小象垃圾分类小程序从开始到结束
    spring boot踩坑记
    spring boot打包问题
  • 原文地址:https://www.cnblogs.com/z360519549/p/11218704.html
Copyright © 2011-2022 走看看