當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。