本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}