spring-data-mongodb

Spring Data Mongo - How to map inherited POJO entities?

被刻印的时光 ゝ 提交于 2019-12-11 07:58:07
问题 I'm fairly new to Spring but I want to give it a try on this project. I have a MongoDB database populated with quite complexe documents. I want to use Spring data Mongo to query (no other CRUD operations) the database. I already described my document entity using POJOs but some of them are abstract (see GeometryGeoJSON is used to accept all type of GeoJson geometry, or Contact that can be a Person or an Organisation . The link to the GitHub repo is provided below). Having a test with that

How to create an Aggregation from a list of AggregationOperation in Spring data MongoDB?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 07:12:28
问题 I want to create an Aggregation that can be used in MongoOperations's aggregate() function. So for creating the Aggregation, I used a list of AggregationOperation as follows: ApplicationContext ctx = new AnnotationConfigApplicationContext(MongoConfig.class); MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate"); List<AggregationOperation> aggregationOperations = new ArrayList<AggregationOperation>(); aggregationOperations.add(new MatchOperation(Criteria.where(

Spring-boot: mongoDB date comparison not working

旧城冷巷雨未停 提交于 2019-12-11 07:07:14
问题 I am trying to get appointments for a particular date. So I am passing fromDate and toDate to find data in that date range. Here is my code, in which query method is changing the actual date passing to it. I have also pasted the query formed by this code in spring boot . DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS\'Z\'"); fromDate = "2017-10-06T00:00:00.000Z"; toDate = "2017-10-07T23:00:00.000Z"; Date startDate,endDate; startDate = dateFormatter.parse(fromDate);

Spring mongoTemplate. Sort is not working in geo query (NearQuery)

浪尽此生 提交于 2019-12-11 06:19:19
问题 I have a problem with mongoTemplate in Spring when I am trying to query using NearQuery with a Sort. The Sort does not work: Query query = new Query(); query.with(new Sort(Direction.DESC, "timeStamp")); Criteria criteria = new Criteria(); criteria.and("type").is("MeasurementPoint"); query.addCriteria(criteria); NearQuery queryN = NearQuery.near(p).maxDistance(new Distance(distance, Metrics.KILOMETERS)).num(range).query(query); GeoResults<MeasurementPoint> geoPoints = mongoTemplate.geoNear

Spring Data MongoDB aggregation - match by calculated value

感情迁移 提交于 2019-12-11 06:15:40
问题 I've got a collection of documents with 2 Number fields and I need to filter all the documents based on a calculated condition: Number1/Number2 >= CONST% How can I make this posible using Spring Data Mongo and Aggregation? --UPDATE-- I've tried the following code: return new RedactAggregationOperation( new BasicDBObject( "$redact", new BasicDBObject( "$cond", new BasicDBObject() .append("if", new BasicDBObject( "$gte", Arrays.asList(new BasicDBObject( "$divide", Arrays.asList( "$Number1", new

POST MongoDB Extended JSON to a RepositoryRestController

梦想与她 提交于 2019-12-11 06:08:17
问题 I'm looking for a smart or elegant way to POST MongoDB Extended JSON to a REST controller of a web service developped with Spring Boot (1.5.1). My POJO contains well defined fields (mostly Strings), but also a Map<String, Object> data with is used to store generic data, meaning its specific structure is unknown at build time, and it will be fed by clients of the webservice. Please don't scold me, I know this is a poor design choice, but I was still asked to "make it happen" :) At some point,

Find spring-data-mongo MappingContext memory leak

丶灬走出姿态 提交于 2019-12-11 05:55:14
问题 I'm debugging a memory leak in my application which uses spring-data-mongodb.1.9.1.RELEASE . MongoMappingContext is using up about a third of the heap . It has a reference to almost 30k PersistentEntity objects totaling over 140MB. This memory leak is caused by holding unnecessary references to MongoDB data objects so they can't be garbage collected. Why might so many of these objects be held in the MappingContext if I never reference these PersistentEntity objects in my code? Does holding on

Autowired error spring

天涯浪子 提交于 2019-12-11 03:43:31
问题 I am new to spring. Previous I have used to configure the auto wiring using spring- context xml. Now my project we are using annotation directly to inject the bean. I am getting following exception when I try to auto wire Mongo repository. Below is the sample code. StagingDocumentServiceImpl: @Service public class StagingDocumentServiceImpl implements StagingDocumentService { private static final Logger logger = Logger.getLogger(StagingDocumentServiceImpl.class); @Autowired private

Which version of Spring Data MongoDB is compatible with Spring 3.2.2.RELEASE?

时光怂恿深爱的人放手 提交于 2019-12-11 03:09:58
问题 I am currently using mongo-java-driver 3.0.1. I am trying to use Spring Data Mongodb with Spring 3.2.2.RELEASE. Is there any way i can find out which version of Spring Data MongoDB should i use, in order to be compatible with Spring 3.2.2.RELEASE? Some kind of compatibility matrix. 回答1: You can check the compiled dependencies of Spring Data Mongodb. Here are the most compatible options for Spring 3.2.2.RELEASE: spring-data-mongodb 1.5.6.RELEASE depends on spring-core 3.2.22.RELEASE spring

Spring Data MongoDB: aggregation framework - sort with nested property throws invalid reference

人走茶凉 提交于 2019-12-11 02:08:22
问题 I found this article in Spring Forum which obviously dicusses partly the same problem, but has no answer to my question. Given the following document... { "_id": { "$oid": "5214b5d529ee12460939e2ba"}, "title": "this is my title", "tags": [ "fun", "sport" ], "comments": [ { "author": "alex", "text": "this is cool", "createdAt": 1 }, { "author": "sam", "text": "this is bad", "createdAt": 2 }, { "author": "jenny", "text": "this is bad", "createdAt": 3 } ] } ... I want to do this aggregation