spring-data-mongodb

Mongo spring-data issue with java.util.Currency

我们两清 提交于 2019-12-10 10:27:24
问题 Getting error "No property null found on entity class java.util.Currency" Hi I have Document Class as @Document @JsonInclude(Include.NON_NULL) public class Course { @Id private String id; private String title; private Currency curr; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Currency getCurr() { return curr; } public void setCurr(Currency curr)

MongoDb equivalent of writer in Spring Batch?

血红的双手。 提交于 2019-12-10 09:50:50
问题 I'm following Spring doc for creating batch service. It implements ItemWriter using JdbcBatchItemWriter , so could you please help me write the MongoDb equivalent of following code using MongoItemWriter ? I found two tutorials using MongoDb, but they use XML files to define beans & seem outdated. @Configuration @EnableBatchProcessing public class BatchConfiguration { // tag::readerwriterprocessor[] @Bean public ItemWriter<Person> writer(DataSource dataSource) { JdbcBatchItemWriter<Person>

Using subtract in a Spring MongoDB group aggregation

故事扮演 提交于 2019-12-10 06:05:20
问题 I have the following aggregation query that works when I use the command line in Mongo. {'$group': { '_id': {'serviceName': '$serviceName'}, 'timeAverage': {'$avg': {'$subtract': ['$lastCheckTime', '$enqueuedTime']} } } } But as far as I can tell, in Spring MongoDB there is no support for doing "subtract" inside of an avg operation in a group operation. How would I go about making this work? 回答1: You could try projecting the difference field first by using the SpEL andExpression in the

How exactly does spring-data-mongodb handle constructors when rehydrating objects?

蓝咒 提交于 2019-12-10 04:34:00
问题 I have read http://static.springsource.org/spring-data/data-mongo/docs/1.1.0.RELEASE/reference/html/#mapping-chapter but cannot find the answer to the following basic spring-data-mongodb object mapping question: If I load an instance of the following class from MongoDB: public class Test { private String str1; private String str2; private Date date3; public Test(String str1) { this.str1 = str1; this.date3=new Date(); } } I understand that the constructor Test(String str1) will be invoked with

Spring Data mongodb: adding credentials for MongoDb access

丶灬走出姿态 提交于 2019-12-09 19:12:36
问题 I have the following working configurations in my Spring application: <mongo:mongo id="myRs" replica-set="myhost:27017"> <mongo:options max-wait-time="1500" connect-timeout="30000" /> </mongo:mongo> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <property name="writeResultChecking" value="EXCEPTION"/> <property name="writeConcern" value="FSYNC_SAFE"/> <constructor-arg ref="myRs"/> <constructor-arg name="databaseName" value="mydb"/> </bean> Now all I want

performance issue on Spring Data Mongodb

蓝咒 提交于 2019-12-09 18:18:39
问题 I've got an issue on spring data mongodb, in a method, I request a simple "find" wich retrieve ~1000 Documents. my spring data code is here : Query myquery = query(where("ipp").is(ipp).and(CODE_MESURE).in(codes).and(DATE_MESURE).gte(iDateDebut).lt(iDateFin)); return template.find(myquery, MessageMongo.class); And with JProfiler, i've got ~1,4sec in the "find" method of MongoTemplate class. Note : The request to MongoDB is not the problem, execution take less than 20ms. But if try to request

Spring data mongoDb not null annotation like Spring data Jpa

冷暖自知 提交于 2019-12-09 15:42:09
问题 Like spring-data-jpa have @NotNull annotation what can be used for this in spring-data-mongodb.? 回答1: javax.validation.constraints.NotNull itself could be used with spring-data-mongodb. For this you need to have following in place. JSR-303 dependencies added in your pom.xml <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>5.3.4.Final</version> </dependency> Declare appropriate validators and validator event listeners import org

Text Search not working with Spring Boot MongoDB

痴心易碎 提交于 2019-12-09 14:18:05
问题 I am developing the Spring Boot + MongoDB + spring data mongo + Text search Example. By taking a reference from link: https://spring.io/blog/2014/07/17/text-search-your-documents-with-spring-data-mongodb, I developed my code, but when I am executing that, it's giving empty resultset. Please help in this scenario. I was expecting to get both results OrderId = 10248 and 10249 , but I got empty. My developed code: OrderDetails.java @Document(collection="order-details") public class OrderDetails

Why Spring ReactiveMongoRepository does't have save method for Mono?

北慕城南 提交于 2019-12-09 03:22:32
问题 I have a MovieRepository which extended ReactiveMongoRepository. I want to save a single POJO in a reactive way. But ReactiveMongoRepository doesn't provide save method for Mono or Publisher. I have to use block() method or use the saveAll method in the ReactiveMongoRepository. public Mono<ServerResponse> create(ServerRequest request) { Mono<Movie> movieMono = request.bodyToMono(Movie.class); return movieRepository.save(movieMono.block()) // .flatMap((movie) -> ServerResponse.ok().body

mongodb multi tenacy spel with @Document

元气小坏坏 提交于 2019-12-09 00:09:59
问题 This is related to MongoDB and SpEL Expressions in @Document annotations This is the way I am creating my mongo template @Bean public MongoDbFactory mongoDbFactory() throws UnknownHostException { String dbname = getCustid(); return new SimpleMongoDbFactory(new MongoClient("localhost"), "mydb"); } @Bean MongoTemplate mongoTemplate() throws UnknownHostException { MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(), new MongoMappingContext()); return new MongoTemplate