spring-data-mongodb

Why is Spring Data MongoDB unable to instantiate this nested type structure?

自古美人都是妖i 提交于 2019-12-03 17:50:36
问题 My document structure is like: { _id: "A", groups:[{ groupId: "someId", groupName: "someName", params: { type1: ["a", "b"], type2: ["c", d] } }], config: { person: {} dataDetails: { dataTypeDetails: {}, dataList: ["dt1", "dt2"] } } } My Spring Data MongoDB model types look like this: // Imports etc. @Document public class Entity { @Id private String _id; private List<Group> groups; private Config config; // setters and getters public class Group { private String groupId; private String

Pagination with mongoTemplate

﹥>﹥吖頭↗ 提交于 2019-12-03 16:47:55
问题 I have a Query with Pageable: Query query = new Query().with(new PageRequests(page, size)) How can I execute it with MongoTemplate ? I don't see a single method returning Page<T> . 回答1: MongoTemplate does not have methods to return Page . The find() methods return an ordinary List . with(new PageRequests(page, size) is used internally to adjust skip and limit with a MongoDB query (proceeded by a count query I think) Page can be used in conjunction with MongoDB repositories which is a

Spring Data mongo to insert null values to DB

百般思念 提交于 2019-12-03 15:57:56
I am using Spring data mongo to insert a record to Mongo, here is my code mongoTemplate.save(person,"personCollection"); Here is my person object public class Person implements Serializable { int age; String address; String name; //Getters and setters including hashcode and equals } my address is null here , after inserting the record in the collection, the data is populated with only age and name i know that mongodb treats null value and noKey as the same thing, but my requirement is to even populate the address:null to have the schema consistent how do i do this with Spring Data mongo

Insert DBObject into MongoDB using Spring Data

久未见 提交于 2019-12-03 13:03:05
I tried to insert the following DBObject into MongoDB using Spring Data: BasicDBObject document = new BasicDBObject(); document.put("country", "us"); document.put("city", "NY"); mongoTemplate.insert(document); where mongoTemplate is my Spring template (org.springframework.data.mongodb.core.MongoTemplate). When executing, I get: Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: No Persitent Entity information found for the class com.mongodb.BasicDBObject at org.springframework.data.mongodb.core.MongoTemplate.determineCollectionName(MongoTemplate.java:1747) at org

Spring data version annotation not incrementing when used on a mongo collection

…衆ロ難τιáo~ 提交于 2019-12-03 12:40:47
问题 I am using spring data with mongodb to store binary data such as images etc I want to maintain a version field to append to the url to cheat the browser from caching images. See my document base class below: import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Version; import org.springframework.data.mongodb.core.index.Indexed; public abstract class BaseDocument { @Id @Indexed(unique=true) protected long id; protected byte[] data; protected String mimeType

How to return only specific fields for a query in Spring Data MongoDB?

谁说胖子不能爱 提交于 2019-12-03 12:13:27
问题 How can we select specific fields in Spring Data Mongo. I tried the following but I got cast exception from Foo to String . Using @Query @Query(value="{path : ?0}", fields="{path : 0}") String findPathByPath(String path); Non @Query String findPathByPath(String path); Here is the document model @Document(collection = "foo") public class Foo { String name, path; … } 回答1: MongoDB only returns JSON documents for standard queries. What you'd like to see can be achieved by still returning a List

Customizing Spring Data repository bean names for use with multiple data sources

自古美人都是妖i 提交于 2019-12-03 11:54:32
I have a project that utilizes Spring Data (MongoDB in this instance) to interact with multiple databases with the same schema. What this means is that each database utilizes the same entity and repository classes. So, for example: public class Thing { private String id; private String name; private String type; // etc... } public interface ThingRepository extends PagingAndSortingRepository<Thing, String> { List<Thing> findByName(String name); } @Configuration @EnableMongoRepositories(basePackageClasses = { ThingRepository.class }) public MongoConfig extends AbstractMongoConfiguration { //

spring-data mongodb custom implementation PropertyReferenceException

北城以北 提交于 2019-12-03 11:04:28
I'm trying to implement a custom query according to the Reference 4.4 Custom Implementations: http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/repositories.html What's the difference between Spring Data's MongoTemplate and MongoRepository? I'm doing this because I need special queries using mongoTemplate. The error I'm getting is a PropertyReferenceException. So it seems that spring-data is trying to auto-generate the query which I don't want. I want to use my own custom query. org.springframework.data.mapping.PropertyReferenceException: No property search

Why is Spring Data MongoDB unable to instantiate this nested type structure?

风格不统一 提交于 2019-12-03 05:57:18
My document structure is like: { _id: "A", groups:[{ groupId: "someId", groupName: "someName", params: { type1: ["a", "b"], type2: ["c", d] } }], config: { person: {} dataDetails: { dataTypeDetails: {}, dataList: ["dt1", "dt2"] } } } My Spring Data MongoDB model types look like this: // Imports etc. @Document public class Entity { @Id private String _id; private List<Group> groups; private Config config; // setters and getters public class Group { private String groupId; private String groupName; private ParamData params; // setter and getters } public class ParamData { private List<String>

Exclude some fields of Spring-data-rest resource

时光毁灭记忆、已成空白 提交于 2019-12-03 05:51:40
I'm trying to use Spring-data-rest with spring-data-mongodb to expose read-only resources. The problem I met, is that I want to have different views of my documents. Let's say I have some private information in a document, I don't want to expose them publicly. So I tried several ways. I read this post https://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring describing how to use JsonView in order to select the fields we want to expose. I've tried like this : @RepositoryRestResource(collectionResourceRel = "recommandation", path = "recommandations") interface