spring-data-mongodb

How to add custom links to non repository rest controller in spring data rest hal?

本秂侑毒 提交于 2020-01-13 22:40:02
问题 I would like to add custom rest controller to be added to the json/hal response of the entry point, together with all the respositories that are added by spring. I'm struggling with this by two problems: How can I add my custom controller so it appears on the entry point together with the links to my repository? How can I decorate with a link to my custom controller on a representation of an entity produced by the repository so I can link to my custom controller? I have struggled for a while

Spring Data MongoDB - Annotation @CreatedDate does not work while using with custom Id field

本秂侑毒 提交于 2020-01-13 11:34:14
问题 I have a simple Persistable Class: public class Profile implements Persistable<String>{ @Id private String username; @CreatedDate public Date createdDate; public Profile(String username) { this.username = username; } @Override public String getId() { return username; } @Override public boolean isNew() { return username == null; } } And a simple repository: public interface ProfileRepository extends MongoRepository<Profile, String> { } My Spring Boot Application class is also annotated with

Why does Spring Data MongoDB not expose events for update…(…) methods?

空扰寡人 提交于 2020-01-13 06:59:11
问题 It appears that the update for mongoOperations do not trigger the events in AbstractMongoEventListener . This post indicates that was at least the case in Nov 2014 Is there currently any way to listen to update events like below? This seems to be quite a big omission if it is the case. MongoTemplate.updateMulti() Thanks! 回答1: This is no oversight. Events are designed around the lifecycle of a domain object or a document at least, which means they usually contain an instance of the domain

Mongotemplate.updateFirst() doesn't update @LastModifiedDate

家住魔仙堡 提交于 2020-01-12 10:09:07
问题 I'm using annotation based configuration. @Configuration @Profile("default") @ComponentScan(basePackages = "com.*") @EnableMongoRepositories @EnableMongoAuditing public class ApplicationDataConfig .... And I also have @LastModifiedDate , @CreatedDate annotation set on fields of type org.joda.time.DateTime . When I use org.springframework.data.mongodb.repository.MongoRepository.save(entity) both the audit fields are updated just fine. But when I use org.springframework.data.mongodb.core

Mongotemplate.updateFirst() doesn't update @LastModifiedDate

◇◆丶佛笑我妖孽 提交于 2020-01-12 10:08:49
问题 I'm using annotation based configuration. @Configuration @Profile("default") @ComponentScan(basePackages = "com.*") @EnableMongoRepositories @EnableMongoAuditing public class ApplicationDataConfig .... And I also have @LastModifiedDate , @CreatedDate annotation set on fields of type org.joda.time.DateTime . When I use org.springframework.data.mongodb.repository.MongoRepository.save(entity) both the audit fields are updated just fine. But when I use org.springframework.data.mongodb.core

Unable to override defaults of Pagination in Spring Boot 2.1.6.RELEASE?

佐手、 提交于 2020-01-11 07:51:53
问题 I am working on Spring Boot Spring Data Mongo Pageable example. I want to set pagination value default page=1 and size=5 , if no one provided any values. Now when user provided any values, I want Pageable object to use those values and not default one. Crated Bug: https://jira.spring.io/browse/DATAMONGO-2313 Its not working in my case. Please guide. I'm not using Spring HATEOAS in my application. @GetMapping() public ResponseEntity<Page<Student>> getAllstudents(Pageable pageable){ return

$elemMatch equivalent in spring data mongodb

筅森魡賤 提交于 2020-01-11 05:30:42
问题 I need to know the equivalent code in spring data mongo db to the code below:- db.inventory.find( { qty: { $all: [ { "$elemMatch" : { size: "M", num: { $gt: 50} } }, { "$elemMatch" : { num : 100, color: "green" } } ] } } ) 回答1: I am able to get the answer. This can be done in Spring data mongodb using following code Query query = new Query(); query.addCriteria(Criteria.where("qty").elemMatch(Criteria.where("size").is("M").and("num").gt(50).elemMatch(Criteria.where("num").is(100).and("color")

Spring Custom Query with pageable

≡放荡痞女 提交于 2020-01-10 14:13:07
问题 I want to to implement pagination in spring application.I know using repository we can implement pagination but we can not write our own query for data retrieve there are limited methods in repository that too there is no method accepting query class. If we want to write our custom query to retrieve data from mongodb we have to use mongotemaplete, as i know with mongotemplate we can not implement pagination. Is there any another way to implement pagination along with db queries. any one can

How to order the result from distinct list in MongoDB via Java Driver?

情到浓时终转凉″ 提交于 2020-01-06 19:39:58
问题 I am using MongoDB via Java Driver (Spring Data MongoDB). Now my code is like: DBObject query = new BasicDBObject("user", user); mongoTemplate.getCollection("reports").distinct("category", query); Right now, the result list is not ordered. I want to it sorting by a ASC order. I have check this question Query MongoDB for ordered distinct values but I only get the answer which order the list by java side. How to order the result in MongoDB side? 回答1: I don't think you can use the Distinct

Multi-tenant mongodb database based with spring data

爱⌒轻易说出口 提交于 2020-01-06 14:06:48
问题 I would like to make my web application that is using mongodb and spring-data multitenat. Basically I would like to replicate all my entities(collections) into different databases. Then (based on some rule as for example the user that is logged in the system) I want to store some entity instance (document) into the right database. For example I have a Service Called DBNameProviderService.getDbName() that dynamically returns me the name of the database. How can I use this service to