spring-data-mongodb

Spring Data MongoDB BigDecimal support

那年仲夏 提交于 2019-12-19 07:27:09
问题 guys I have a doubt related to BigDecimal value support by Spring Data MongoDB, could someone help me with some news about it, if there will be support for this type, or if anyone knows a workaround to supply my needs. That's the deal: I'm working on a project where we use MongoDB as a DB and Spring as framework, we would like to save the fields where we are supposed to get money values in the database as BigDecimal, I've read that mongo only accepts double as a float number, but I don't

SD MongoDB polymorphism in subdocument

狂风中的少年 提交于 2019-12-19 04:08:45
问题 I just started developing some app in Java with spring-data-mongodb and came across some issue that I haven't been able to solve: Have a couple of document beans like this: @Document(collection="myBeanBar") public class BarImpl implements Bar { String id; Foo foo; // More fields and methods ... } @Docuemnt public class FooImpl implements Foo { String id; String someField; // some more fields and methods ... } And I have a repository class with a method that simply invokes a find similar to

Spring Data Mongo + Lazy Load + REST Jackson

早过忘川 提交于 2019-12-18 17:24:50
问题 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

How to configure spring-data-mongodb to use a replica set via properties

Deadly 提交于 2019-12-18 11:47:00
问题 I am currently writing an application which should use a replica set of MongoDB. It is a Spring Boot based application and the following properties work perfectly fine to connect to one server: spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=demo This is absolutely fine for my local dev environment. But later on it should run against a MongoDB replica set, so I have to provide at least 2, better 3 replica set seeds, but how can I do this with

How to prevent some HTTP methods from being exported from my MongoRepository?

感情迁移 提交于 2019-12-18 10:34:39
问题 I'm using spring-data-rest and I have a MongoRepository like this: @RepositoryRestResource interface MyEntityRepository extends MongoRepository<MyEntity, String> { } I would like to allow the GET methods but disable PUT, POST, PATCH and DELETE (read only web service). According to http://docs.spring.io/spring-data/rest/docs/2.2.2.RELEASE/reference/html/#repository-resources.collection-resource I should be able to do that like this: @RepositoryRestResource interface MyEntityRepository extends

Does Spring Data MongoDb support $filter array aggregations operator?

不打扰是莪最后的温柔 提交于 2019-12-18 09:38:40
问题 I'm trying to implement in Spring Data using MongoTemplate the following working mongoDb query: db.answers.aggregate([ { "$match" : { "object_id" : "1" } }, { "$project": { 'answer_list': 1, 'profile': { $filter : { input: '$answer_list', as: 'answer', cond: { $eq: [ '$$answer.question', 2 ] } } } } }, { "$unwind" : "$profile"}, { "$unwind" : "$answer_list"}, { "$group" : { "_id" : { "question" : "$answer_list.question", "answer" : "$answer_list.answer", "criteria" : "$profile.answer"},

How to customize MappingMongoConverter (setMapKeyDotReplacement) in Spring-Boot without breaking the auto-configuration?

痞子三分冷 提交于 2019-12-18 07:42:59
问题 How could I customize the MappingMongoConverter within my Spring-Boot-Application (1.3.2.RELEASE) without changing any of the mongo-stuff which is autoconfigured by spring-data? My current solution is: @Configuration public class MongoConfig { @Autowired private MongoDbFactory mongoFactory; @Autowired private MongoMappingContext mongoMappingContext; @Bean public MappingMongoConverter mongoConverter() throws Exception { DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoFactory);

Spring Data MongoDB Repository - JPA Specifications like

天涯浪子 提交于 2019-12-18 06:58:28
问题 Is there something like JPA Specifications for Spring Data MongoDB Repositories? If not, how can I make dynamic queries with repositories? A classic scenario could be a search form with optional fields that the user will fill. 回答1: I found myself a way. The trick can be done using QueryDSL , in the following way: First, add the QueryDSL dependencies: <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-mongodb</artifactId> <version>${querydsl-mongo.version}</version> <

Optional cannot be returned by stream() in Mockito Test classes

时光怂恿深爱的人放手 提交于 2019-12-18 05:26:09
问题 I am developing Test cases for the Spring Data Mongo Services. org.mockito.exceptions.misusing.WrongTypeOfReturnValue: Optional cannot be returned by stream() stream() should return Stream *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. This exception *might* occur in wrongly written multi-threaded tests. Please refer to Mockito FAQ on limitations of concurrency testing. 2. A spy is stubbed using when(spy.foo()

How to Get Only Matched Result from An Array Field of Document in Mongo Using Spring Data

此生再无相见时 提交于 2019-12-18 05:10:23
问题 I am using spring boot 1.5.1 and MongoDB version 3.4.6 . I have a mongo document Hotel which has a list of Review . The Review class has property userName . @Document public class Hotel { @Id private String id; private List<Review> reviews; I want to search all the hotel by Review userName. My HotelRepository has public List<Hotel> findByReviewsUserName(String userName); When I am calling with user 'Salman' - List<Hotel> list = this.hotelRepository.findByReviewsUserName(user); this method