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
  • 相关阅读:
    qml 无边框
    Qt 参考链接
    QPushButton QSS
    Head First设计模式之备忘录模式
    Head First设计模式之访问者模式
    Head First设计模式之状态模式
    web打印总结
    Head First设计模式之单例模式
    .Net IOC框架入门之一 Unity
    第五章 MVC之Bundle详解
  • 原文地址:https://www.cnblogs.com/z360519549/p/11218704.html
Copyright © 2011-2022 走看看