本文整理匯總了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;
}