spring-data-mongodb

MongoRepository get only specific field as result

*爱你&永不变心* 提交于 2019-12-11 17:33:54
问题 i am using Mongodb in Spring Web. And use MongoRepository to CRUD I had: Collection: User Later, i had to create a Group. because i shouldn't and can't embedded User into Group. I create new collection as SQL name: GroupUser. In here, i use: @Field("groupId") private String groupId; @DBRef private User user; this will help to query list user in Group (query data and auto get User's content) But as i want to get the list User's Id. Normally, in SQL we can do like: select user.id from GroupUser

how to use spel to represent $cond of mongo

给你一囗甜甜゛ 提交于 2019-12-11 15:57:39
问题 I have a collection with documents like below { "_id" : ObjectId("5946360fdab24b1d05fac7e6"), "name" : "aaa", "createdAt" : NumberLong("1497773583563"), "segmentedStatus" : 0 } I want to stat how many documents with segmentedStatus = 1, db.foo.aggregate( {$project: {_id:0, segmentedCount:{$cond: [{$eq:["$segmentedStatus",1]}, 1, 0]} } }, {$group: {_id:null, count:{$sum:"$segmentedCount"}}} ) In spring data mongo Aggregation aggregation = newAggregation(project().and("segmentedCount")

How to express complex $sum grouping expression in Spring Data MongoDB

自闭症网瘾萝莉.ら 提交于 2019-12-11 15:28:31
问题 I have following MongoDB aggregation query that works well in MongoDB [ { $match: { "myfield":"X" }, { $group: { _id: { myfield: "$myfield" }, count: { $sum: 1 }, lt5w: { $sum: { $cond:{ if: { $gte: [ "$myDate", new Date(ISODate().getTime() - 1000 * 60 * 60 * 24 * 7 * 5) ] }, then: 1, else: 0 } } }, gt12w: { $sum: { $cond:{ if: { $gte: [ new Date(ISODate().getTime() - 1000 * 60 * 60 * 24 * 7 * 12), "$myDate" ] }, then: 1, else: 0 } } } } } ]) How can I express this complex $sum operation

Spring Aggregation Framework: How to create nested $divide, $subtract, $mod query?

假如想象 提交于 2019-12-11 13:52:10
问题 I'm trying to create a ProjectionOperation in the Java Spring aggregation framework. The following simplified raw mongo db query works fine and should be implemented with java code. I'm struggling with the first row in the $project section of my query. How can I write nested project queries in the aggregation framework? (side note: startTime is a fixed and given unix timestamp) db.procedure_executions.aggregate([ { $match : { "application.$id" : ObjectId("55144929bc26f48fb5de15a7") } }, {

No suitable constructor found for type GeoJsonPoint

雨燕双飞 提交于 2019-12-11 13:11:35
问题 Having a lot of trouble figuring out what I'm doing wrong. Sadly I had it working at one point, but can't determine what I changed that broke it. From what I understand this should be fully supported now. Object in question: @Document public class Place { public final static String URI = "/place"; @Id private String id; private String name; private String caption; private GeoJsonPoint location; public Place() {} public Place(GeoJsonPoint geoJsonPoint) { this.location = geoJsonPoint; } //

spring data mongodb “id” field mapping

情到浓时终转凉″ 提交于 2019-12-11 11:29:33
问题 I have a document with an array field with "chapters": [ { "id" : "14031871223912313", ...} ... ] I would like to query return the id's with Spring Data's MongoTemplate using the following: class Chapter { private String id; public String getId() { return id; } } This way the id is not populated. I have tried using the different mapping options with @Field described here http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mapping.conventions.id-field What am I doing wrong?

how to run mongodb native query with mongodb date function in spring-data-mongodb?

佐手、 提交于 2019-12-11 10:57:19
问题 I want to execute the below native query in spring data mongodb : db.runCommand({aggregate:"mycollection", pipeline :[{$match : {$and : [{"orderDate" : {$gte : ISODate("2016-07-25T10:33:04.196Z")}}, {"orderDate" : {$lte :ISODate("2018-07-25T10:33:04.196Z") }} ]}}, { "$project" : { "orderType" : 1 ,"count" : 1 , "month" : { "$month" : [ "$orderDate"]}}}, { "$group" : { "_id" : { "month" : "$month" , "orderType" : "$orderType"} , "count" : { "$sum" : 1} }}], cursor:{batchSize:1000}}) I tried

Spring Integration Aggregator with MongoDbMessageStore: Failed to instantiate GenericMessage: No default constructor found

喜你入骨 提交于 2019-12-11 10:17:00
问题 I'm using Spring Integration 4.3.11 with Spring Data MongoDB 1.10.6. I have a message aggregator that uses MongoDbMessageStore . When a message from a message sequence comes in, it's persisted in MongoDB, but immediately after that (in o.s.i.store.AbstractMessageGroupStore#addMessageToGroup ) an exception is thrown when the same message is read from MongoDB that Failed to instantiate [org.springframework.messaging.support.GenericMessage]: No default constructor found Full stacktrace: org

mongotemplate aggregation with unique results

末鹿安然 提交于 2019-12-11 10:16:19
问题 I am using mongotemplate , my collection look like this: { "_id": "theid", "tag": "taga", "somefield": "some value", "fieldC": { "anotherfielad": "more data", "an_array": [ { "a": "abc", "b": 5 }, { "a": "bca", "b": 44 }, { "a": "ddd", "b": 21 } ] } } { "_id": "anotherid", "tag": "taga", "somefield": "some other value", "fieldC": { "anotherfielad": "other more data", "an_array": [ { "a": "ccc", "b": 6 }, { "a": "abc", "b": 99 }, { "a": "ddd", "b": 21 } ] } } I need to get a unique result from

Spring Data MongoDB error

断了今生、忘了曾经 提交于 2019-12-11 10:15:31
问题 I am trying to use MongoDB with Java and Spring. I am getting the following error when I try load my application: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 32 in XML document from file [E:\adaptor-JPSS-SA-RE_ssamanta_20150904-025119\bin\..\cfg\spring\beans.xml] is invalid; nes c: The matching wildcard is strict, but no declaration can be found for element 'mongo:mongo'. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions