spring-data-mongodb

Spring data deleteBy query doesnt return deleted object

∥☆過路亽.° 提交于 2020-08-08 06:37:53
问题 In Spring-data-mongodb, can we return the single deleted object from query method of repository like below public interface MyRepository extends MongoRepository<MyObject, String>{ Optional<MyObject> deleteByXAndY(String x, String y); } if there will be always single document that's get deleted by above query. I tried it but it throws exception like cant convert Long to MyObject. I think only void, long or List or Stream are supported. Is there any way to achieve what I am trying to do? 回答1:

Spring data deleteBy query doesnt return deleted object

纵然是瞬间 提交于 2020-08-08 06:37:37
问题 In Spring-data-mongodb, can we return the single deleted object from query method of repository like below public interface MyRepository extends MongoRepository<MyObject, String>{ Optional<MyObject> deleteByXAndY(String x, String y); } if there will be always single document that's get deleted by above query. I tried it but it throws exception like cant convert Long to MyObject. I think only void, long or List or Stream are supported. Is there any way to achieve what I am trying to do? 回答1:

Spring Data Mongo - How to get the nested distinct array for nested value?

ぃ、小莉子 提交于 2020-07-19 23:02:54
问题 I'm taking a reference from : Spring Data Mongo - Perform Distinct, but doesn't wants to pull embedded documents in results and asking another questions. I want to find technology list where "subdeptCd" : "1D". How can we do that ? { "firstName" : "Laxmi", "lastName" : "Dekate", ..... ....... ..... "departments" : { "deptCd" : "Tax", "deptName" : "Tax Handling Dept", "status" : "A", "subdepts" : [ { "subdeptCd" : "1D", "subdeptName" : "Tax Clearning", "desc" : "", "status" : "A" "technology"

Spring Data Mongo - How to get the nested distinct array for nested value?

99封情书 提交于 2020-07-19 23:02:21
问题 I'm taking a reference from : Spring Data Mongo - Perform Distinct, but doesn't wants to pull embedded documents in results and asking another questions. I want to find technology list where "subdeptCd" : "1D". How can we do that ? { "firstName" : "Laxmi", "lastName" : "Dekate", ..... ....... ..... "departments" : { "deptCd" : "Tax", "deptName" : "Tax Handling Dept", "status" : "A", "subdepts" : [ { "subdeptCd" : "1D", "subdeptName" : "Tax Clearning", "desc" : "", "status" : "A" "technology"

Spring Data MongoDB auditing doesn't work for embedded documents

牧云@^-^@ 提交于 2020-07-18 10:55:31
问题 I'm trying to introduce auditing by using Spring Data MongoDB @LastModifiedDate annotation. It works fine for top-level documents but I've faced with the problem for embedded objects. For example: @Document(collection = "parent") class ParentDocument { @Id String id; @LastModifiedDate DateTime updated; List<ChildDocument> children; } @Document class ChildDocument { @Id String id; @LastModifiedDate DateTime updated; } By default, when I save parentDocument instance with inner children list,

How to do a Mongo aggregation query in Spring Data?

折月煮酒 提交于 2020-07-14 11:13:06
问题 It's the first time I am using Mongo in Java and I am having some problems with this aggregation query. I can do some simple queries in Mongo for Spring with @Query annotation in my Repository interface which extends the MongoRepository<T, ID> . It would be helpful to know which approach to take when you do long aggregations in Spring-Data. db.post.aggregate([ { $match: {} }, { $lookup: { from: "users", localField: "postedBy", foreignField: "_id", as: "user" } }, { $group: { _id: { username:

How to do a Mongo aggregation query in Spring Data?

本秂侑毒 提交于 2020-07-14 11:12:02
问题 It's the first time I am using Mongo in Java and I am having some problems with this aggregation query. I can do some simple queries in Mongo for Spring with @Query annotation in my Repository interface which extends the MongoRepository<T, ID> . It would be helpful to know which approach to take when you do long aggregations in Spring-Data. db.post.aggregate([ { $match: {} }, { $lookup: { from: "users", localField: "postedBy", foreignField: "_id", as: "user" } }, { $group: { _id: { username:

Spring Data MongoDB - lazy access to some fields

蓝咒 提交于 2020-07-09 06:44:19
问题 Is it possible to mark field of the class that it will be lazy-loaded? Example: public class Dictionary { private String id; private String someDescription; private String someInfo; private Map<String, String> dictionary; } I want to mark "dictionary" field to be lazy-accessed. Why? This field can be huge and I need it only sometimes, not always. For example I have another object that contains a lot of Dictionary. And its main purpose is to present information from all contained Dictionaries

SpringData mongoDB API for Aggregation $map

▼魔方 西西 提交于 2020-07-08 01:14:37
问题 Following is my Native MongoDB query and below is the SpringData Mongo API equivalent. I am getting struck on using $map in $project in SpringData Mongo API. Appreciate your help on completing my conversion to API db.users.aggregate([ { $match: {$and : [{userType:"200"} }, { $unwind: "$userOrgMap" }, { $lookup: { from: "users", localField: "userOrgMap.createdbyuser", foreignField: "_id", as: "created_by" } }, {$project:{ _id:"$_id", login:"$login", firstName:"$firstName", lastName:"$lastName"

SpringData mongoDB API for Aggregation $map

我们两清 提交于 2020-07-08 01:13:44
问题 Following is my Native MongoDB query and below is the SpringData Mongo API equivalent. I am getting struck on using $map in $project in SpringData Mongo API. Appreciate your help on completing my conversion to API db.users.aggregate([ { $match: {$and : [{userType:"200"} }, { $unwind: "$userOrgMap" }, { $lookup: { from: "users", localField: "userOrgMap.createdbyuser", foreignField: "_id", as: "created_by" } }, {$project:{ _id:"$_id", login:"$login", firstName:"$firstName", lastName:"$lastName"