当前位置: 首页>>代码示例>>Java>>正文


Java MongoTemplate.find方法代码示例

本文整理汇总了Java中org.springframework.data.mongodb.core.MongoTemplate.find方法的典型用法代码示例。如果您正苦于以下问题:Java MongoTemplate.find方法的具体用法?Java MongoTemplate.find怎么用?Java MongoTemplate.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.data.mongodb.core.MongoTemplate的用法示例。


在下文中一共展示了MongoTemplate.find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateUserAddAddress

import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
/**
 * update v3: {@link UserDocument} has changed; an embedded Document 'address' was added.
 *
 * @since V4
 */
@ChangeSet(order = "004", id = "addAddressToUser", author = "admin")
public void updateUserAddAddress(final MongoTemplate template) {
  final List<UserDocument> userList = template.find(Query.query(Criteria.where("email").is("[email protected]")), UserDocument.class);
  userList.stream()
      .map(userDocument -> {
        userDocument.getUserAddress()
            .addAll(
                Stream.iterate(0, n -> n + 1)
                    .limit(new Random().nextInt(5))
                    .map(it -> new Address("Hamburger City", "Random Muster Straße " + it, it + "5678"))
                    .collect(Collectors.toList()));
        return userDocument;
      })
      .forEach(template::save);
}
 
开发者ID:nkolytschew,项目名称:mongobee_migration_example,代码行数:21,代码来源:DatabaseChangeLog.java

示例2: main

import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
    MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
    BasicQuery basicQuery = new BasicQuery("{apply_id:{$gt:800}}");
    List<FkApply> find = mongoTemplate.find(basicQuery, FkApply.class);
    System.out.println(find.size());
    find.forEach(System.out::println);
}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:9,代码来源:MapReduceOperations.java

示例3: main

import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
    MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
    BasicQuery basicQuery = new BasicQuery("{apply_id:{$gt:800}}");
    List<FkApply> find = mongoTemplate.find(basicQuery, FkApply.class);
    System.out.println(find.size());
    find.forEach(System.out::println);

    // Projection Expressions
    System.err.println("Projection Expressions");
    Aggregation aggregation = Aggregation.newAggregation(
            Aggregation.project("apply_id", "apply_type"));
    AggregationResults<OutputType> aggregate = mongoTemplate.aggregate(aggregation, "fk_qc_apply", OutputType.class);
    aggregate.forEach(System.out::println);
}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:16,代码来源:AggregationOperations.java

示例4: main

import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
    MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);

    List<FkApply> find = mongoTemplate.find(Query.query(Criteria.where("apply_id").gt(1000).and("cost_center.type").gt(1)), FkApply.class);
    System.out.println(find.size());
    find.forEach(System.out::println);

}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:13,代码来源:QueryingDocumentsInACollection.java

示例5: main

import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
    MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
    BasicQuery basicQuery = new BasicQuery("{apply_id:{$gt:800}}");
    List<FkApply> find = mongoTemplate.find(basicQuery, FkApply.class);
    System.out.println(find.size());
    find.forEach(System.out::println);

}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:10,代码来源:QueryingDocuments.java

示例6: dataRepository

import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Bean
DataRepository dataRepository(MongoTemplate mongoTemplate) {
    return (String application, List<String> profiles, List<String> labels) ->
            mongoTemplate.find(new Query(), DataPropertySource.class, application);
}
 
开发者ID:cynicLT,项目名称:spring-cloud-config-server-data,代码行数:6,代码来源:MongoDataConfigServerTest.java

示例7: performQuery

import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
/**
 * Performs actual Query. This method can be overridden by subclasses in order
 * to deal with non-Mongo searches.
 *
 * @param queryComponent
 *     the query component.
 * @param context
 *     the action context
 * @return the list of retrieved components.
 */
@Override
@SuppressWarnings({"unchecked", "ConstantConditions"})
public List<?> performQuery(final IQueryComponent queryComponent, final Map<String, Object> context) {
  MongoTemplate mongo = ((MongoBackendController) getController(context)).getMongoTemplate();
  IQueryFactory qFactory = (IQueryFactory) queryComponent.get(CRITERIA_FACTORY);
  if (qFactory == null) {
    qFactory = getQueryFactory(context);
    queryComponent.put(CRITERIA_FACTORY, qFactory);
  }
  Query query = qFactory.createQuery(queryComponent, context);
  List<? extends IEntity> entities;
  Class<? extends IEntity> entityClass = queryComponent.getQueryContract();
  if (query == null) {
    entities = new ArrayList<>();
    queryComponent.setRecordCount(0);
  } else {
    IQueryRefiner critRefiner = (IQueryRefiner) queryComponent.get(CRITERIA_REFINER);
    if (critRefiner == null) {
      critRefiner = getQueryRefiner(context);
      if (critRefiner != null) {
        queryComponent.put(CRITERIA_REFINER, critRefiner);
      }
    }
    if (critRefiner != null) {
      critRefiner.refineQuery(query, queryComponent, context);
    }
    Integer totalCount = null;
    Integer pageSize = queryComponent.getPageSize();
    Integer page = queryComponent.getPage();

    if (pageSize != null) {
      if (page == null) {
        page = 0;
        queryComponent.setPage(page);
      }
      if (queryComponent.getRecordCount() == null) {
        if (isUseCountForPagination()) {
          totalCount = (int) mongo.count(query, entityClass);
        } else {
          totalCount = IQueryComponent.UNKNOWN_COUNT;
        }
      }
      qFactory.completeQueryWithOrdering(query, queryComponent, context);
      entities = mongo.find(query.skip(page * pageSize).limit(pageSize), entityClass);
    } else {
      qFactory.completeQueryWithOrdering(query, queryComponent, context);
      entities = mongo.find(query, entityClass);
      totalCount = entities.size();
    }
    if (totalCount != null) {
      queryComponent.setRecordCount(totalCount);
    }
  }
  List<String> prefetchProperties = queryComponent.getPrefetchProperties();
  if (prefetchProperties != null && entities != null) {
    // Will load the prefetch properties in the same transaction in order to leverage
    // Mongo batch fetching.
    IAccessorFactory accessorFactory = getAccessorFactory(context);
    for (String prefetchProperty : prefetchProperties) {
      for (IEntity entity : entities) {
        try {
          accessorFactory.createPropertyAccessor(prefetchProperty, entityClass).getValue(
              entity);
        } catch (Exception e) {
          LOG.warn("An unexpected exception occurred when pre-fetching property {}", prefetchProperty, e);
        }
      }
    }
  }
  return entities;
}
 
开发者ID:jspresso,项目名称:jspresso-ce,代码行数:82,代码来源:QueryEntitiesAction.java


注:本文中的org.springframework.data.mongodb.core.MongoTemplate.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。