spring-data-mongodb

No converter found capable of converting from type java.lang.String to type @org.springframework.data.repository.query.Param

假如想象 提交于 2019-11-30 20:59:03
问题 I'm building a MongoDb rest application with spring boot 1.1.5. I have created a repository: @RepositoryRestResource(collectionResourceRel = "SourceProductV1Repository", path = "SourceProductV1Repository") public interface SourceProductV1Repository extends MongoRepository<SourceProductV1Model, String> { public List<SourceProductV1Model> findByUser (@Param("user") MongoUser user); } I Defined a converter to convert String to MongoUser (the converter is correctly registered in the spring

Storing java 8 LocalDate in mongo DB

依然范特西╮ 提交于 2019-11-30 20:43:06
Using Spring boot 1.5.4.RELEASE and Mongo driver 3.4.2 . I want to store LocalDate in mongo DB , but I am facing a weird problem. LocalDate startDate = LocalDate.now(); LocalDate endDate = LocalDate.of(2020,12,01); System.out.println("---- StartDate : ---"+startDate); System.out.println("-----End Date : ----"+endDate); repository.save(new Person("Mehraj","Malik", startDate, endDate)); Output on Console : ---- StartDate : ---2017-08-26 -----End Date : ----2020-12-01 But In MongoDb it is storing incorrect dates. Following is the json from MongoDb : "startDate" : ISODate("2017-08-25T18:30:00.000Z

Spring Data Mongodb - repository for collection with different types

时间秒杀一切 提交于 2019-11-30 20:05:33
I have a mongo collection that may contain three types of entities that I map to java types: Node LeafType1 LeafType2 Collection is ment to store tree-like structure using dbRefs of child nodes in parent entry. I didn't find any information about subject in Spring reference documentation so I'm asking here: Is there a way to use Repository mechanism to work with collection that may contain different types of objects? Declaring several repositories for different types in one collection seems like not very good idea because I always struggle with situations when queried object is not of expected

How apply pagination in reactive Spring Data?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 19:16:41
In Spring Data, we have PagingAndSortingRepository which inherits from CrudRepository . In reactive Spring Data, we only have ReactiveSortingRepository which inherits from ReactiveCrudRepository . How could we make pagination in a reactive way ? Will we able to make this in future with ReactivePagingAndSortingRepository for instance? Reactive Spring Data MongoDB repositories do not provide paging in the sense of paging how it's designed for imperative repositories. Imperative paging requires additional details while fetching a page. In particular: The number of returned records for a paging

Spring Data Mongodb Repositories don't implement inheritance correctly

允我心安 提交于 2019-11-30 18:52:13
Having two types of entities, that are mapped to two Java classes in the single MongoDB collection: @Document public class Superclass { ... } @Document(collection = "superclass") public class Subclass extends Superclass { ... } and two repositories for those entities: public interface SuperclassRepository extends MongoRepository<Superclass, String> {} public interface SubclassRepository extends MongoRepository<Subclass, String> {} MongoRepositories don't handle the inheritance of the entities correctly. While querying for all Subclass objects (e.g. SubclassRepository.findAll() ) the result set

Spring Data mongo - issue with Distinct collection

社会主义新天地 提交于 2019-11-30 16:42:57
Spring Data Mongo distinct doesn't works. I've following two documents. /* 1 */ { "_id" : ObjectId("5ca746fd92bc0733a4a6633b"), "firstName" : "John", "lastName" : "Kerr", "emailId" : "john.kerr@gmail.com", "hobbies" : [ { "interest" : "Indoor", "sports" : "Chess" }, { "interest" : "Loveoor", "sports" : "Table Tennis" } ], "_class" : "com.example.Person" } /* 2 */ { "_id" : ObjectId("5ca746fd92bc0733a4a6633c"), "firstName" : "Neha", "lastName" : "Parate", "emailId" : "john.kerr@gmail.com", "hobbies" : [ { "interest" : "Indoor", "sports" : "Chess" }, { "interest" : "Loveoor", "sports" : "Table

How to execute blocking calls within a Spring Webflux / Reactor Netty web application

半世苍凉 提交于 2019-11-30 15:34:31
问题 In my use case where I have a Spring Webflux microservice with Reactor Netty, I have the following dependencies: org.springframework.boot.spring-boot-starter-webflux (2.0.1.RELEASE) org.springframework.boot.spring-boot-starter-data-mongodb-reactive (2.0.1.RELEASE) org.projectreactor.reactor-spring (1.0.1.RELEASE) For a very specific case I need to retrieve some information from my Mongo database, and process this into query parameters send with my reactive WebClient . As the WebClient nor the

mongodb multi tenacy spel with @Document

三世轮回 提交于 2019-11-30 15:34:29
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(mongoDbFactory(), converter); } I have a tenant provider class @Component("tenantProvider") public class

Spring Data Mongo + Lazy Load + REST Jackson

断了今生、忘了曾经 提交于 2019-11-30 15:29:14
Hello I have some issues with Spring and Mongo with Lazy Load. I have this configuration: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> This Document: @Document public class User { @Id private String id; @DBRef private Place place; @DBRef(lazy=true)

How to execute blocking calls within a Spring Webflux / Reactor Netty web application

偶尔善良 提交于 2019-11-30 14:17:34
In my use case where I have a Spring Webflux microservice with Reactor Netty, I have the following dependencies: org.springframework.boot.spring-boot-starter-webflux (2.0.1.RELEASE) org.springframework.boot.spring-boot-starter-data-mongodb-reactive (2.0.1.RELEASE) org.projectreactor.reactor-spring (1.0.1.RELEASE) For a very specific case I need to retrieve some information from my Mongo database, and process this into query parameters send with my reactive WebClient . As the WebClient nor the UriComponentsBuilder accepts a Publisher (Mono / Flux) I used a #block() call to receive the results.