Spring Data Mongo Repository
Spring Data Mongo Repository 是一个基于 Spring 框架的、用于简化 MongoDB 操作的 Repository 接口。它为开发者提供了丰富的功能,便于进行 MongoDB 数据库的操作和管理。以下是一些通用共享方法:
List<T> findAll();
List<T> findByIds(List<ObjectId> ids);
List<T> findByField(String field, Object value);
PageRequest pageRequest = new PageRequest(0, 10);
List<T> pageResult = findAllByPage(pageRequest);
Sort sort = new Sort(Sort.Direction.ASC, "field");
List<T> sortedResult = findAllBySort(sort);
List<T> limitResult = findAll().limit(10).skip(5).get();
long insertCount = save(entity);
boolean updated = update(entity).where(new Criteria().and(new Criteria().equal("fieldName", "value"))).update("fieldName", "newValue").execute();
boolean deleted = delete(entity).where(new Criteria().and(new Criteria().equal("fieldName", "value"))).execute();
List<String> indexNames = mongoTemplate.indexOps(Entity.class).getIndexNames();
mongoTemplate.indexOps(Entity.class).createIndex(new IndexModel(IndexType.DESC, "fieldName"));
List<String> unshardedCollections = mongoTemplate.collections();
List<ShardInfo> shardInfos = mongoTemplate.shardInfo();
mongoTemplate.changeShardCollection(collectionName);
mongoTemplate.removeShardCollection(collectionName);
List<String> unshardedCollections = mongoTemplate.collections();
List<ShardInfo> shardInfos = mongoTemplate.shardInfo();
mongoTemplate.changeShardCollection(collectionName);
mongoTemplate.removeShardCollection(collectionName);
List<String> unshardedCollections = mongoTemplate.collections();
List<ShardInfo> shardInfos = mongoTemplate.shardInfo();
mongoTemplate.changeShardCollection(collectionName);
mongoTemplate.removeShardCollection(collectionName);
List<String> unshardedCollections = mongoTemplate.collections();
List<ShardInfo> shardInfos = mongoTemplate.shardInfo();
mongoTemplate.changeShardCollection(collectionName);
mongoTemplate.removeShardCollection(collectionName);
List<String> unshardedCollections = mongoTemplate.collections();
List<ShardInfo> shardInfos = mongoTemplate.shardInfo();
3
领取专属 10元无门槛券
手把手带您无忧上云