spring-mongo

Spring not using mongo custom converters

房东的猫 提交于 2019-12-01 02:44:10
问题 I have been trying to register my own write custom converters to change the default ID value. But it never actually calls. Here is my Custom Converter public class EventKeyConverter implements Converter<Event,DBObject> { @Override public DBObject convert(Event object) { DBObject dbObject = DBObjectTransformer.toDBObject(object); dbObject.put("_id", KeyGenerator.getRandomKey()); return dbObject; } } here is the place that I did register customer converter @Override @Bean public

Difference between MongoFactoryBean and SimpleMongoDbFactory

两盒软妹~` 提交于 2019-11-30 19:36:20
I am setting up a MongoDB Spring MVC application and trying to use Service, DAO pattern. I read the Spring-Data-MongoDB refernce here , but I am not understanding what is the differnce between MongoFactoryBean and SimpleMongoDbFactory. What would be a better way, and why, to create a MongoTemplate bean. @Configuration public class SpringMongoConfig { public @Bean MongoDbFactory mongoDbFactory() throws Exception { return new SimpleMongoDbFactory(new MongoClient(), "yourdb"); } public @Bean MongoTemplate mongoTemplate() throws Exception { MongoTemplate mongoTemplate = new MongoTemplate

Aggregation Project Group By extracted day, month and year with Spring Data

我的梦境 提交于 2019-11-30 14:15:39
问题 To be direct, how do i do this: group._id = { year: { $year : [{ $subtract: [ "$timestamp", 25200000 ]}] }, month: { $month : [{ $subtract: [ "$timestamp", 25200000 ]}] }, day: { $dayOfMonth : [{ $subtract: [ "$timestamp", 25200000 ]}] } }; with spring Data I tried this already and some other forms and were not successfull Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(c), Aggregation.project("programa", "custo", "duracao", "dataHora") .andExpression("dataHora").minus

Aggregation Project Group By extracted day, month and year with Spring Data

北战南征 提交于 2019-11-30 10:20:41
To be direct, how do i do this: group._id = { year: { $year : [{ $subtract: [ "$timestamp", 25200000 ]}] }, month: { $month : [{ $subtract: [ "$timestamp", 25200000 ]}] }, day: { $dayOfMonth : [{ $subtract: [ "$timestamp", 25200000 ]}] } }; with spring Data I tried this already and some other forms and were not successfull Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(c), Aggregation.project("programa", "custo", "duracao", "dataHora") .andExpression("dataHora").minus(25200000).extractDayOfMonth().as("dia") .andExpression("dataHora").minus(25200000).extractMonth().as(

How to update particular array element in MongoDB

孤者浪人 提交于 2019-11-30 09:51:37
问题 I am newbie in MongoDB. I have stored data inside mongoDB in below format "_id" : ObjectId("51d5725c7be2c20819ac8a22"), "chrom" : "chr22", "pos" : 17060409, "information" : [ { "name" : "Category", "value" : "3" }, { "name" : "INDEL", "value" : "INDEL" }, { "name" : "DP", "value" : "31" }, { "name" : "FORMAT", "value" : "GT:PL:GQ" }, { "name" : "PV4", "value" : "1,0.21,0.00096,1" } ], "sampleID" : "Job1373964150558382243283" I want to update the value to 11 which has the name as Category . I

Difference between MongoFactoryBean and SimpleMongoDbFactory

自闭症网瘾萝莉.ら 提交于 2019-11-30 03:46:49
问题 I am setting up a MongoDB Spring MVC application and trying to use Service, DAO pattern. I read the Spring-Data-MongoDB refernce here, but I am not understanding what is the differnce between MongoFactoryBean and SimpleMongoDbFactory. What would be a better way, and why, to create a MongoTemplate bean. @Configuration public class SpringMongoConfig { public @Bean MongoDbFactory mongoDbFactory() throws Exception { return new SimpleMongoDbFactory(new MongoClient(), "yourdb"); } public @Bean

How to update particular array element in MongoDB

牧云@^-^@ 提交于 2019-11-29 16:49:56
I am newbie in MongoDB. I have stored data inside mongoDB in below format "_id" : ObjectId("51d5725c7be2c20819ac8a22"), "chrom" : "chr22", "pos" : 17060409, "information" : [ { "name" : "Category", "value" : "3" }, { "name" : "INDEL", "value" : "INDEL" }, { "name" : "DP", "value" : "31" }, { "name" : "FORMAT", "value" : "GT:PL:GQ" }, { "name" : "PV4", "value" : "1,0.21,0.00096,1" } ], "sampleID" : "Job1373964150558382243283" I want to update the value to 11 which has the name as Category . I have tried below query: db.VariantEntries.update({$and:[ { "pos" : 117199533} , { "sampleID" :

$filter inside $project MongoDB Using Spring Data

馋奶兔 提交于 2019-11-29 12:49:37
I have a subdocument that is an array of a parent document. "devices" In that array I've got a property which is a Date property. I want to find the parents documents who contains the child subdocuments by determinated date like this: { "_id" : ObjectId("5818fa596969a1339093a7da"), "fecha" : ISODate("2016-11-01T05:00:00.000Z"), "spot" : "5808e3926969a126c8365c94", "devices" : [ { "evaluationDate" : ISODate("2016-11-01T20:26:00.000Z"), "seenTimesCounter" : 0, "category" : "PRE_PASAJERO", "status" : "NO_CONECTADO" }, { "evaluationDate" : ISODate("2016-11-01T20:26:00.000Z"), "seenTimesCounter" :

Mongodb $lookup in Spring data mongo

余生颓废 提交于 2019-11-28 10:25:50
I'm a new Mongodb and I have a problem with $lookup with java spring. I would like to use this shell in Spring data db.NewFeed.aggregate([ { $match : {username : "user001"} }, { $lookup: { from: "NewfeedContent", localField: "content.contentId", foreignField: "_id", as: "NewfeedContent" } } ]) I found on Google but no answer yet. Not every "new" feature makes it immediately into abstraction layers such as spring-mongo . So instead, all you need do is define a class that uses the AggregationOperation interface, which will instead take a BSON Object specified directly as it's content: public

Spring -Mongodb storing/retrieving enums as int not string

自作多情 提交于 2019-11-28 00:20:12
问题 My enums are stored as int in mongodb (from C# app). Now in Java, when I try to retrieve them, it throws an exception (it seems enum can be converted from string value only). Is there any way I can do it? Also when I save some collections into mongodb (from Java), it converts enum values to string (not their value/cardinal). Is there any override available? This can be achieved by writing mongodb-converter on class level but I don't want to write mondodb-converter for each class as these