spring-data-mongodb

@CompoundIndex not working in Spring Data MongoDB

試著忘記壹切 提交于 2019-12-30 06:26:11
问题 I am working on an application using Spring Data MongoDB. I would like to create a compound index on one of my models. I have added a @CompoundIndex annotation at the top like so: @Document @CompoundIndexes({ @CompoundIndex(name = "name_", def = "{ 'tenantId': 1, 'name': 1 }", unique = true) }) public class MyModel { } However, the index is not created. I have also tried to directly place the @CompoundIndex above the class. The collection is still missing the index. The same index definition

spring data mongodb group by

蹲街弑〆低调 提交于 2019-12-28 19:01:05
问题 I am using spring data Mongodb in my project and refer the below classes for my query on grouping the results: Student class: @Document(collection = "student") public class Student { @Id private String id; private String firstName; private String lastName; //other fields //getters & setters } StudentResults (dto): public class StudentResults { private String firstName; private List<String> studentIds; //I need List<Student> here public String getFirstName() { return firstName; } public void

spring data mongodb group by

别说谁变了你拦得住时间么 提交于 2019-12-28 19:00:07
问题 I am using spring data Mongodb in my project and refer the below classes for my query on grouping the results: Student class: @Document(collection = "student") public class Student { @Id private String id; private String firstName; private String lastName; //other fields //getters & setters } StudentResults (dto): public class StudentResults { private String firstName; private List<String> studentIds; //I need List<Student> here public String getFirstName() { return firstName; } public void

Persisting objects containing primitive arrays with spring-data-mongodb

試著忘記壹切 提交于 2019-12-25 10:18:23
问题 I'm using spring-data-mongodb version 1.1.1.RELEASE . I am able to persist an object if all the member variables are primitive types, even if the names of the @PersistenceConstructor arguments don't match exactly the names of the member variables by using the @Field("foo") and @Value("#root.foo") annotations. However, I get a MappingInstantiationException (Illegal arguments for constructor) when I try to persist objects that contain primitive arrays. This holds true regardless of whether the

@RepositoryRestResource's collectionResourceRel attribute not being obeyed

血红的双手。 提交于 2019-12-25 08:59:53
问题 I have a MongoRepository of @RepositoryRestResource(collectionResourceRel = "tools") public interface ToolRepository extends MongoRepository<Tool, Long> Tool can be one of 2 implementations: public class Screwdriver extends Tool public class Hammer extends Tool Tool is mapped using @JsonTypeInfo @JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.CLASS, include = As.PROPERTY, property = "_class") public abstract class Tool When I do toolRepository.findAll() this returns a

How to set @TextIndex name in an entity with Spring-Data-MongoDB

不羁的心 提交于 2019-12-25 07:50:11
问题 I have a entity Person , inherited by Musician and Politician and a repository PersonRepository. I am trying to have all three entities saved into the a collection "person" in MongoDB using PersonRepository.save(..) default method but somehow, Spring-Data-MongoDB save it into 3 separate collections "person", "musician" and "politician". Java Code: @Document public class Person { @Id private String id; @Indexed private String name; @TextIndexed private String biography; } @Document public

Spring Data MongoDB NotLike - Unsupported keyword

南笙酒味 提交于 2019-12-25 06:46:07
问题 I have configured a Spring Data Repository (mongoDB) and Author entity as following : Repository : public interface AuthorRepository extends MongoRepository< Author, Long > { Iterable<Author> findByFirstName( String personName ); Iterable<Author> findByFirstNameLike( String personName ); Iterable<Author> findByFirstNameNotLike( String firstName ); } Entity Class : @Document( collection = "author" ) @Data public class Author { @Id private String id; private String firstName; //.. } I'm able to

spring data mongo repository is null

随声附和 提交于 2019-12-25 04:22:09
问题 I am writing a standalone java program that call spring data repository for manging enities. I am using mongo db for persistence. I am following stackoverflow posts and some projects from github but when I run my program it fails since the repository is null. I am not expert in spring so it would be helpful if someone could show me the issue with the posted program. Application-context.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns

Spring boot 1.2.1 No qualifying bean of type found for dependency

守給你的承諾、 提交于 2019-12-25 03:32:30
问题 I have upgraded from spring boot version 1.1.5 to 1.2.1 and now I get NoSuchBeanDefinitionException . I have simple main class @Configuration @ComponentScan @EnableAutoConfiguration public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } and later I have repo @Repository public interface UserRepository extends MongoRepository<User, String>, UserRepositoryCustom { ... } custom repo public interface UserRepositoryCustom { // custom

Spring boot 1.2.1 No qualifying bean of type found for dependency

情到浓时终转凉″ 提交于 2019-12-25 03:32:30
问题 I have upgraded from spring boot version 1.1.5 to 1.2.1 and now I get NoSuchBeanDefinitionException . I have simple main class @Configuration @ComponentScan @EnableAutoConfiguration public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } and later I have repo @Repository public interface UserRepository extends MongoRepository<User, String>, UserRepositoryCustom { ... } custom repo public interface UserRepositoryCustom { // custom