spring-data-mongodb

Collection based multitenancy with Spring Data MongoDB

最后都变了- 提交于 2019-12-01 18:08:44
问题 Our Spring Boot 1.3.3 application persists data on MongoDB (2.6 ou 3.2) using Spring Data MongoDB 1.8.4. We need to support multitenancy. We chose to use "collection based" multitenancy, i.e. each tenant has its own set of collection. For example for the Article entity, the collections are "{tenantName}_articles". Oliver Gierke kindly explained an implementation in Making spring-data-mongodb multi-tenant using for example : @Document(collectionName = "#{tenantProvider.getTenantId()}_articles"

find distinct embedded documents from the document using Spring Data Mongo?

安稳与你 提交于 2019-12-01 14:48:55
How to remove duplicates from the embedded documents using the Spring Data Mongo or MongoTemplate or MongoOperations? If I do db.inventory.distinct( "hobbies" ) This gives me all distinct hobbies, but if I do like below then I don't get distinct records. Sample Documents: { "_id" : ObjectId("592c7029aafef820f432c5f3"), "_class" : "lankydan.tutorial.mongodb.documents.Person", "firstName" : "John", "secondName" : "Doe", "dateOfBirth" : ISODate("2017-05-29T20:02:01.636+01:00"), "address" : [ { "addressLineOne" : "19 Imaginary Road", "addressLineTwo" : "Imaginary Place", "city" : "Imaginary City",

NoClassDefFoundError after upgrading to 1.7.0.RELEASE

僤鯓⒐⒋嵵緔 提交于 2019-12-01 14:02:09
I was trying to upgrade my application from 1.6.2.RELEASE to 1.7.0.RELEASE in my playframework project. Insert queries are working fine but there seems to be an issue when spring-data tries to inflate the object using class name after fetching result against query, if there's no result against query then it returns an empty arraylist without throwing error. 1.7.0.RELEASE works fine in another project based on spring-integration framework. below is statck trace :- java.lang.NoClassDefFoundError: models/db/nosql/ACME models.db.nosql.ACME_Instantiator_gtblf6.newInstance(Unknown Source) org

find distinct embedded documents from the document using Spring Data Mongo?

感情迁移 提交于 2019-12-01 13:32:48
问题 How to remove duplicates from the embedded documents using the Spring Data Mongo or MongoTemplate or MongoOperations? If I do db.inventory.distinct( "hobbies" ) This gives me all distinct hobbies, but if I do like below then I don't get distinct records. Sample Documents: { "_id" : ObjectId("592c7029aafef820f432c5f3"), "_class" : "lankydan.tutorial.mongodb.documents.Person", "firstName" : "John", "secondName" : "Doe", "dateOfBirth" : ISODate("2017-05-29T20:02:01.636+01:00"), "address" : [ {

NoClassDefFoundError after upgrading to 1.7.0.RELEASE

▼魔方 西西 提交于 2019-12-01 13:24:38
问题 I was trying to upgrade my application from 1.6.2.RELEASE to 1.7.0.RELEASE in my playframework project. Insert queries are working fine but there seems to be an issue when spring-data tries to inflate the object using class name after fetching result against query, if there's no result against query then it returns an empty arraylist without throwing error. 1.7.0.RELEASE works fine in another project based on spring-integration framework. below is statck trace :- java.lang

Why Spring ReactiveMongoRepository does't have save method for Mono?

↘锁芯ラ 提交于 2019-12-01 11:04:30
I have a MovieRepository which extended ReactiveMongoRepository. I want to save a single POJO in a reactive way. But ReactiveMongoRepository doesn't provide save method for Mono or Publisher. I have to use block() method or use the saveAll method in the ReactiveMongoRepository. public Mono<ServerResponse> create(ServerRequest request) { Mono<Movie> movieMono = request.bodyToMono(Movie.class); return movieRepository.save(movieMono.block()) // .flatMap((movie) -> ServerResponse.ok().body(fromObject(movie))); } Is there a better way to solve this kind of problem? I don't think use block method is

Random documents from MongoDB using spring-data

廉价感情. 提交于 2019-12-01 06:29:11
I'm able to do it by using this mongodb native query : db.books.aggregate( [ { $sample: { size: 15 } } ] ) But how to do it in spring-data-mongodb ? I found no similar operation in Aggregation class of Spring Aggregation Framework Blakes Seven Update: Starting with v2.0 of Spring Data you can do this: SampleOperation matchStage = Aggregation.sample(5); Aggregation aggregation = Aggregation.newAggregation(sampleStage); AggregationResults<OutType> output = mongoTemplate.aggregate(aggregation, "collectionName", OutType.class); Original answer: Abstraction layers like spring-mongo are always going

Spring Data MongoDB: BigInteger to ObjectId conversion

好久不见. 提交于 2019-12-01 06:05:34
I have a problem with update query using Spring Data MongoDB. I retrieve some object's _id as BigInteger value. Then I want to make following query: Query query = new Query(Criteria.where("_id").is(id)); Update update = new Update(); update.set("version",version); mongoOperations.updateFirst(query, update, Audit.class); Query part fails to match any documents since id value passed to is() somehow must be converted to ObjectId. I can't find any documentation on this kind of conversion. Will appreciate any help. p.s.: SpringData Mongodb version 1.2 Maciej Walkowiak You can convert it also

How to map document with dynamic keys to a Spring MongoDb entity class

陌路散爱 提交于 2019-12-01 06:04:58
I have a document that can have dynamic key names: { "_id" : ObjectId("51a29f6413dc992c24e0283e"), "envinfo" : { "appName" : "MyJavaApp", "environment" : { "cpuCount" : 12, "heapMaxBytes" : 5724766208, "osVersion" : "6.2", "arch" : "amd64", "javaVendor" : "Sun Microsystems Inc.", "pid" : 44996, "javaVersion" : "1.6.0_38", "heapInitialBytes" : 402507520, } Here envinfo 's keys are not known in advance. What is the best way to create an entity class in Spring Data Mongodb which will map this document? This is one way of doing it. There may be other better ways. Create a map of attributes and

PersistenceConstructor argument variable name doesn't match instance variable name

梦想的初衷 提交于 2019-12-01 06:03:58
I'm trying to persist the following object with spring-data-mongodb version 1.1.1.RELEASE : @Document public static class TestObject { private final int m_property; @PersistenceConstructor public TestObject(int a_property) { m_property = a_property; } public int property() { return m_property; } } I get a MappingException when I try to read the object back from the database (see full stacktrace below) The naming convention my group uses requires argument variable names to be prefaced by a_ and instance variable names to be prefaced by m_ . It seems like spring-data-mongodb is making the