spring-data-mongodb

how to use $lookup stage in java with spring data mongodb? [duplicate]

六月ゝ 毕业季﹏ 提交于 2020-01-02 07:23:15
问题 This question already has an answer here : lookup in mongodb aggregation (1 answer) Closed last year . Up to last version of spring i have seen lot of stack over flow questions which shows there is no support for this operation in spring-data-mongodb is there any support for this operation in new spring-data-mongodb 1.10.0 db.orders.aggregate([ { $lookup: { from: "inventory", localField: "item", foreignField: "sku", as: "inventory_docs" } } ]) 回答1: Lookup support has been there since 1.9

How to update document in mongo to get performance?

杀马特。学长 韩版系。学妹 提交于 2020-01-02 04:06:08
问题 I am new to Spring Data Mongo . I've a scenario where I want to create a Study if already not present in mongo db. If its already present, then I've to update it with the new values. I tried in the following way, which works fine in my case, but I'm not sure this is the correct/Best/Advisable way to update etc as far as performance is concerned. Could anyone please guide on this? public void saveStudy(List<Study> studies) { for (Study study : studies) { String id = study.getId(); Study

How to compare 2 fields in Spring Data MongoDB using query object

别说谁变了你拦得住时间么 提交于 2020-01-01 16:50:14
问题 What seems almost natural in simple SQL is impossible in mongodb . Given a simple document: { "total_units" : 100, "purchased_unit" : 60 } I would like to query the collection, using spring data Criteria class, where "total_units > purchased_units" . To my understanding it should be as trivial as any other condition. Found nothing to support this on Spring api. 回答1: I don't think Spring Data API supports this yet but you may need to wrap the $where query in your Java native DbObject. Note,

how to pivot data using spring-data-mongodb

笑着哭i 提交于 2020-01-01 07:21:10
问题 I have data of this form and I referred to this link pivoting in mongodb: Name, SumPrice, type,year A, 50.0, Retail,2015 B, 467.0, Online,2015 A, 1456.0, Direct,2015 B, 1149.53, Direct,2015 C, 273.20, Online,2014 C, 110.0, Direct,2014 I want data to be transformed using spring-data-mongodb of this form Name ,Retail, Online , Direct, year A, 50.0 , 0.0, 1456.0 2015 B, 0.0, 467.0, 1149.53, 2015 C, 0.0, 273.20, 110.0, 2014 Please lemme know how to do. Regards kris 来源: https://stackoverflow.com

Exclude some fields of Spring-data-rest resource

大兔子大兔子 提交于 2020-01-01 02:25:09
问题 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 :

MongoDB - Storing date without timezone

末鹿安然 提交于 2019-12-31 01:27:28
问题 We have a simple application in which we have all user in same timezone & therefore we are not interested to store timezone information in mongo date object. Reason for such extreme step is we have multiple micro service using common database managed by different developers. Each of them requires to explicitly set timezone related stuff in query & forgetting same results in invalid dataset. Since currently MongoDB folks Mongo Data Types doesn't support storing dates without timezone. Just

MongoDB and SpEL Expressions in @Document annotations

五迷三道 提交于 2019-12-30 07:32:29
问题 I am trying to use the SpEL to load the same Document into different collections based on some rules that i have defined. So to start with what i have: -first of all the document: @Document(collection = "#{@mySpecialProvider.getTargetCollectionName()}") public class MongoDocument { // some random fields go in } -second i have the provider bean that should provide the collection name: @Component("mySpecialProvider") public class MySpecialProvider { public String getTargetCollectionName() { //

Storing java 8 LocalDate in mongo DB

佐手、 提交于 2019-12-30 06:36:48
问题 Using Spring boot 1.5.4.RELEASE and Mongo driver 3.4.2 . I want to store LocalDate in mongo DB , but I am facing a weird problem. LocalDate startDate = LocalDate.now(); LocalDate endDate = LocalDate.of(2020,12,01); System.out.println("---- StartDate : ---"+startDate); System.out.println("-----End Date : ----"+endDate); repository.save(new Person("Mehraj","Malik", startDate, endDate)); Output on Console : ---- StartDate : ---2017-08-26 -----End Date : ----2020-12-01 But In MongoDb it is

Storing java 8 LocalDate in mongo DB

不打扰是莪最后的温柔 提交于 2019-12-30 06:34:13
问题 Using Spring boot 1.5.4.RELEASE and Mongo driver 3.4.2 . I want to store LocalDate in mongo DB , but I am facing a weird problem. LocalDate startDate = LocalDate.now(); LocalDate endDate = LocalDate.of(2020,12,01); System.out.println("---- StartDate : ---"+startDate); System.out.println("-----End Date : ----"+endDate); repository.save(new Person("Mehraj","Malik", startDate, endDate)); Output on Console : ---- StartDate : ---2017-08-26 -----End Date : ----2020-12-01 But In MongoDb it is

@CompoundIndex not working in Spring Data MongoDB

自闭症网瘾萝莉.ら 提交于 2019-12-30 06:26:22
问题 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