spring-mongodb

Mongo db java unwind operation in aggregate query throwing exception

隐身守侯 提交于 2020-01-05 04:57:22
问题 When working with embedded mongo document I am trying to unwind the array but I am getting exception like org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments. The query what I wrote is, Aggregation agg = newAggregation( unwind("recipients"), match(Criteria.where("recipients.userId").is("800").andOperator(Criteria.where("recipients.status").is(false) ))); Logs.java private String id; private

How to merge two matching objects from different array into one object?

社会主义新天地 提交于 2020-01-03 03:23:10
问题 I have a situation where I have got one result from aggregation where I am getting data in this format. { "_id" : ObjectId("5a42432d69cbfed9a410e8ad"), "bacId" : "BAC0023444", "cardId" : "2", "defaultCardOrder" : "2", "alias" : "Finance", "label" : "Finance", "for" : "", "cardTooltip" : { "enable" : true, "text" : "" }, "dataBlocks" : [ { "defaultBlockOrder" : "1", "blockId" : "1", "data" : "0" }, { "defaultBlockOrder" : "2", "blockId" : "2", "data" : "0" }, { "defaultBlockOrder" : "3",

How to filter array in Mongodb document using Spring

六眼飞鱼酱① 提交于 2019-12-25 09:28:13
问题 I have below document structure. { "_id" : { "teacherId" : "<teacherId>", "Year" : "<Year>" }, "groups" : [ { "groupId" : "<uuid>", "groupName" : "<name>", "groupNameLowerCase" : "<name_in_lower_case>", "description" : "<desc>", "students" : ["<studentid1>", "<studentid2>", ...], "editedDate" : "<currentTimestamp>" }, ... ], "editedDate" : "<currentTimestamp>", "points" : "<points>" } Consider that below two documents are present in DB { "_id" : { "teacherId" : "1", "Year" : "2016" }, "groups

Use $mergeObjects inside ReplaceRoot pipeline stage in Spring MongoDB

早过忘川 提交于 2019-12-24 03:44:22
问题 i'm looking to reproduce this snipet into Java code : db.getCollection('admins_comptes_client_ceov4').aggregate([ {$lookup: {from: "contrats_ceov4",localField: "CUSTOMERNUMBER",foreignField: "CUSTOMERNUMBER",as: "arrayForeignObject"} {$unwind: { path: "$arrayForeignObject", preserveNullAndEmptyArrays: true}}, {$replaceRoot: { newRoot: { $mergeObjects: [ "$arrayForeignObject", "$$ROOT" ] } }}, { $project: { "arrayForeignObject": 0, "_id": 0 } }, { $out: "aggregate" }]) I'm here so far :

INFO warnings about multiple modules in Spring Boot, what do they mean?

≡放荡痞女 提交于 2019-12-21 06:47:30
问题 I recently bumped up my spring boot version to 1.4.0. Now I see the following warnings below. I am using spring-mongodb and spring-redis (strictly for caching). Is this something I should be concerned about? Multiple Spring Data modules found, entering strict repository configuration mode! Spring Data Redis - Could not safely identify store assignment for repository What does strict repository configuration mode really mean? . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '

Remove items from array of documents in Spring+Mongo

妖精的绣舞 提交于 2019-12-20 04:13:29
问题 I have a collection of documents like this in a mongo db : "_id" : ObjectId("592bc37c339e7a23788b4c7c"), "trips" : [ { "tripGcsId" : "5937f86e339e7a2a58ac3186", "tripCounter" : NumberLong(1283), "tripRef" : "hjkhjk" }, { "tripGcsId" : "5937f914339e7a2a58ac318b", "tripCounter" : NumberLong(1284), "tripRef" : "fjh" } ] and a method on the server side (Spring+Mongo): public List<String> removeTripObject( List<String> tripIds ) { Query query = Query.query( Criteria.where( "trips" ).elemMatch(

How to get Count of aggregation query in spring mongo template

好久不见. 提交于 2019-12-14 02:19:34
问题 I'm using spring mongo template to run an agreegation query on mongodb. I'm wondering is there any way to find out the count of aggregation result in spring mongo template? Here is my Aggregation sample : Aggregation agg = newAggregation(Class1.class, match(criteria), group("prop1", "prop2") .avg("x").as("averageX") ); I just need to know how to get count of this aggregation result in spring mongo template. 回答1: My response comes very late but it might help others. To get the count for an

How build Spring Data Mongo Aggregation Operations using for-loop

我是研究僧i 提交于 2019-12-13 03:58:14
问题 The following example works perfectly. MatchOperation matchStage = mongodbConstructorQueryUtils.makeMatchStage(topCriteria); GroupOperation groupStage = Aggregation.group("teamId", "teamName") .sum("shotsOfOneAttempted").as("sumShotsOfOneAttempted") .sum("shotsOfTwoAttempted").as("sumShotsOfTwoAttempted") .sum("shotsOfThreeAttempted").as("sumShotsOfThreeAttempted") .addToSet("idMatchCallExt").as("matches"); ProjectionOperation projectionOperation = Aggregation.project("matches") .and(

Where do the “target” properties in my JSON serialization come from?

别来无恙 提交于 2019-12-13 03:35:13
问题 I have a spring boot service using MongoDB as a repository for my beans. I added a feature to download a bean in JSON format and upload it on another system (or simply to have a file backup). I am using the ObjectMapper with the writeValueAsString method. This all works as expected, except that there are additional properties which aren't part of my bean. All properties that are defined with @DBRef thus pointing to other beans in the MongoDB have a target property containing the exact same

Spring Mongodb fetch data using DBRef association

不问归期 提交于 2019-12-12 14:12:11
问题 I have a retailer class with nested dbref of Address. I would like to fetch retailers based on city which is part of Address class. But I am getting below error. org.springframework.data.mapping.model.MappingException: Invalid path reference address.city! Associations can only be pointed to directly or via their id property! Could you please let me know what's wrong and how to fix this? Code is given below @Document(collection="retailer") @TypeAlias("retailer") public class Retailer extends