spring-data-mongodb

How to use spring data mongo @CompoundIndex with sub collections?

拥有回忆 提交于 2019-11-30 07:23:55
Assume that I have such entities like the following: @Document(collection = "doc_a") public class A { @Field("id") private Integer id; @Field("b") private Collection<B> b; ... } public class B { @Field("id") private Integer id; ... } is it possible to use a compoundIndex with respect to A.id AND B.id together? I mean maybe like: @CompoundIndex(name = "aid_bid_idx", def = "{'id', 'b.id'}") Thanks in advance. I've tried this kind of compound index in my app, that use spring data too, and worked properly. You only have to correct the index definition in @CompoundIndex annotation: @CompoundIndex

How to aggregate in spring data mongo db a nested object and avoid a PropertyReferenceException?

爷,独闯天下 提交于 2019-11-30 06:09:22
问题 I am creating a new endpoint in springboot that will return simple stats on users generated from an aggregate query in a mongo database. However I get a PropertyReferenceException . I have read multiple stackoverflow questions about it, but didn't find one that solved this problem. We have a mongo data scheme like this: { "_id" : ObjectId("5d795993288c3831c8dffe60"), "user" : "000001", "name" : "test", "attributes" : { "brand" : "Chrome", "language" : "English" } } The database is filled with

Spring Data Mongodb - repository for collection with different types

♀尐吖头ヾ 提交于 2019-11-30 04:50:53
问题 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

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

和自甴很熟 提交于 2019-11-30 04:50:32
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 properties? I had a look on this page: http://docs.spring.io/spring-boot/docs/current/reference/html

How apply pagination in reactive Spring Data?

旧时模样 提交于 2019-11-30 03:16:34
问题 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? 回答1: Reactive Spring Data MongoDB repositories do not provide paging in the sense of paging how it's designed for imperative repositories. Imperative paging

Spring Data Mongodb Repositories don't implement inheritance correctly

大城市里の小女人 提交于 2019-11-30 02:56:10
问题 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

Spring data mongodb auditing not working.. (Java config)

你说的曾经没有我的故事 提交于 2019-11-30 02:37:32
问题 i'm currently using Spring data mongodb 1.6.0-RELEASE and i know it has auditing feature. I put @EnableMongoAuditing annotation on top of my configuration class. And my bean is below: @Document public class MyBean{ @Id private AnotherCustomBean anotherCustomBean = new AnotherCustomBean(); @CreatedDate private Date creationDate; @LastModifiedDate private Date lastModifiedDate; . . . When i save this bean with mongoTemplate.save(myBean); it's not setting created date and last modified date..

How to disable spring-data-mongodb autoconfiguration in spring-boot

若如初见. 提交于 2019-11-30 00:05:38
Has anyone tried disabling autoconfiguration for mongodb in spring-boot? I am trying out spring-boot with spring-data-mongodb; Using java based configuration; Using spring-boot 1.2.1.RELEASE, I import spring-boot-starter-web and its' parent pom for dependency management. I also import spring-data-mongodb (tried spring-boot-starter-mongodb as well). I need to connect to two different MongoDB servers. So I need to configure two sets of instances for mongo connection, MongoTemplate etc. I also want to disable auto-configuration. Since I am connecting to multiple servers, I don't need to have a

Spring Data mongo - issue with Distinct collection

試著忘記壹切 提交于 2019-11-30 00:03:10
问题 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",

Does Spring Data MongoDb support $filter array aggregations operator?

夙愿已清 提交于 2019-11-29 18:03:35
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"}, "count" : { "$sum" : 1 } } }, { "$sort" : { "_id.question" : 1, "_id.answer" : 1 } } ]); The collection has