spring-data

How to log the queries executed by Spring Data MongoDB?

允我心安 提交于 2021-02-04 05:41:17
问题 Is there a way to find the query that was run against the database in spring data mongodb? I know this is possible in case of JPA. So was just wondering if there was something similar in Spring data MongoDB? 回答1: The easiest way is to set the log level to DEBUG for org.springframework.data.mongodb . 回答2: logging: level: org.springframework.data.mongodb.core.MongoTemplate: DEBUG To clarify Oliver's answer add that to the application.yml file or properties file. 来源: https://stackoverflow.com

How to add a json in a nested array of a mongodb document using Spring?

五迷三道 提交于 2021-02-02 10:01:06
问题 Document stored in mongodb: { "CNF_SERVICE_ID":"1", "SERVICE_CATEGORY":"COMMON_SERVICE", "SERVICES":[{ "SERVICE_NAME":"Authentication Service", "VERSIONS":[{ "VERSION_NAME":"AuthenticationServiceV6_3", "VERSION_NUMBER":"2", "VERSION_NOTES":"test", "RELEASE_DATE":"21-02-2020", "OBSOLETE_DATE":"21-02-2020", "STATUS":"Y", "GROUPS":[{ "GROUP_NAME":"TEST GROUP", "CREATED_DATE":"", "NODE_NAMES":[ "" ], "CUSTOMERS":[{ "CUSTOMER_CONFIG_ID":"4", "ACTIVATION_DATE":"21-02-2020", "DEACTIVATION_DATE":"21

How to add a json in a nested array of a mongodb document using Spring?

别等时光非礼了梦想. 提交于 2021-02-02 09:58:16
问题 Document stored in mongodb: { "CNF_SERVICE_ID":"1", "SERVICE_CATEGORY":"COMMON_SERVICE", "SERVICES":[{ "SERVICE_NAME":"Authentication Service", "VERSIONS":[{ "VERSION_NAME":"AuthenticationServiceV6_3", "VERSION_NUMBER":"2", "VERSION_NOTES":"test", "RELEASE_DATE":"21-02-2020", "OBSOLETE_DATE":"21-02-2020", "STATUS":"Y", "GROUPS":[{ "GROUP_NAME":"TEST GROUP", "CREATED_DATE":"", "NODE_NAMES":[ "" ], "CUSTOMERS":[{ "CUSTOMER_CONFIG_ID":"4", "ACTIVATION_DATE":"21-02-2020", "DEACTIVATION_DATE":"21

Spring-Data elastic search repo count with custom @Query annotation not working “Expected 1 but found 30 results”

有些话、适合烂在心里 提交于 2021-01-29 19:56:18
问题 For my application I have to perform a custom count on elastic, I want to use the @Query annotation for this in the ElasticsearchCrudRepository we use. When I use the following signature: @Query("CUSTOM BOOL QUERY HERE") long countItemsCustom(); This leads to a java.lang.IllegalArgumentException: Expected 1 but found 30 results Exception since it is executed as an query instead of an count. For spring-data-cassandra we have a special @CountQuery annotation to solve this issue. Is there a

How to perform Bulk Operation in MongoDB (similar to jdbdTemplate.batchUpdate() in Spring)? [duplicate]

送分小仙女□ 提交于 2021-01-29 14:48:08
问题 This question already has answers here : Java MongoDB save multiple documents at once (4 answers) Closed 11 months ago . jdbcTemplate.batchUpdate("INSERT INTO TABLE_NAME (COL1, COL2, COL3) VALUES (?, ?, ?)", List<Object[]>); Is there a similar way that I can do same insert using MongoRepository Interfaces in Spring data mongodb and java ? 回答1: You can insert multiple documents into the collection using one of the following methods. Assuming a test collection and a Test.java POJO representng a

Get all the buckets for a aggregate elastic search

天大地大妈咪最大 提交于 2021-01-29 09:01:54
问题 I want to get all the buckets available for a particular aggregate. Is there any query or endpoint to get the buckets? Below is my Mapping. If I query with any filter then the related buckets are coming up, but I want all the buckets to show it on the frontend to have or operations. Example: If we have 2 records, one is with category as chair and the other is in the table. If I select a chair it is returning table count is zero but it should show as table count as 1. So user can select both.

@Document doesn't create a collection in spring boot application

假如想象 提交于 2021-01-29 06:33:48
问题 I have a simple spring boot rest application. Trying to create a collection using @Document annotation in spring data mongo db. I know spring framework creates a collection if the document is denoted with @Document annotation. Entity @Document("User") public class User { @Id private String Id; @Field("firstName") @TextIndexed private String firstName; @Field("lastName") @TextIndexed private String lastName; private String address; public String getId() { return Id; } public void setId(String

Transactional annotation doesn't solve org.hibernate.LazyInitializationException

北战南征 提交于 2021-01-29 06:20:04
问题 I'm writing a simple Spring Data JPA application. I use MySQL database. There are two simple tables: Department Employee Each employee works in some department (Employee.department_id). I have two entity classes: @Entity public class Department { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id private Long id; @Basic(fetch = FetchType.LAZY) @OneToMany(mappedBy = "department") List<Employee> employees; } @Entity public class Person { @GeneratedValue(strategy = GenerationType.IDENTITY)

Using JPA repository access in constructor of Service class

半世苍凉 提交于 2021-01-29 05:25:44
问题 I have spring boot app with a service (annotated @Service ) and having several JPA repository interfaces. Now I want to read entries form a database during the start of the service cause the JPA repository and the database connection is done before anything else. So I have decided to put that code into the constructor of the service. The question is: Is this a correct way to initialise some attributes of a service only once at the start of the application (configuration which is stored in

Spring + MongoDB - MongoTemplate + Criteria Query

这一生的挚爱 提交于 2021-01-29 05:01:32
问题 I am using Spring Boot + MongoDB. I need to query database based on some criteria where my methods looks like below: @Override public List<MyCollection> findBuyByCriteria(Request request) { Query search = new Query(); search.addCriteria(Criteria.where("ItmId").in(request.getItmIds())); return mongoTemplate.find(search, MyCollection.class); } Problem that I am facing is: At line search.addCriteria(Criteria.where("ItmId").in(request.getItmIds())); request.getItmIds has 1 million Ids due to