【问题标题】:Capped collections using MongoDB and SpringData使用 MongoDB 和 Spring Data 限制集合
【发布时间】:2012-07-25 17:14:29
【问题描述】:

我正在尝试使用 mongoTemplate 创建一个用于记录的上限集合。但是,我的集合大小正在增长超出我作为参数传递的大小。谁能帮忙解决这个问题。

public synchronized MongoTemplate getTemplate() {

    if (template == null) {
        Mongo mongo = null;
        mongo = new Mongo(addrs);
        template = new MongoTemplate(mongo, this.dbName);

        if(!template.collectionExists(HttpRequestEntity.class)){
            CollectionOptions options = new CollectionOptions(4,4,true);
            template.createCollection(HttpRequestEntity.class, options);
        }   
    }

    return template;
}

为了保存,我在这个模板实例上调用 save

getTemplate().save(entity);

【问题讨论】:

    标签: mongodb logging spring-data


    【解决方案1】:

    在我从 mongo 控制台删除集合后,它就可以工作了。我猜这是使用旧的元数据,因为 template.collectionExists(HttpRequestEntity.class) 正在返回 true。

    【讨论】:

      猜你喜欢
      • 2011-12-15
      • 2018-05-12
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多