Questions tagged [spring-data-mongodb]

Spring Data for MongoDB is part of the Spring Data project which provides a familiar and consistent Spring-based programming model for new datastores while retaining store-specific features and capabilities. The Spring Data MongoDB project provides integration with MongoDB document database. Key functional areas of Spring Data MongoDB are a POJO centric model for interacting with a MongoDB Collection and easily writing a Repository style data access layer.

Spring Data for MongoDB is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for new datastores while retaining store-specific features and capabilities.

The Spring Data MongoDB project provides integration with the MongoDB document database. Key functional areas of Spring Data MongoDB are a POJO centric model for interacting with a MongoDB DBCollection and easily writing a Repository style data access layer

Features

  • Spring configuration support using Java based @Configuration classes or an XML namespace for a Mongo driver instance and replica sets.
  • MongoTemplate and ReactiveMongoTemplate helper classes that increase productivity performing common Mongo operations.
  • Fluent Template API.
  • Support for MongoDB Transactions.
  • Listener containers for Change Streams and Tailable cursors.
  • Includes integrated object mapping between documents and POJOs.
  • Exception translation into Spring's portable Data Access Exception hierarchy.
  • Feature Rich Object Mapping integrated with Spring's Conversion Service.
  • Annotation based mapping metadata but extensible to support other metadata formats.
  • Persistence and mapping lifecycle events.
  • Low-level mapping using MongoReader/MongoWriter abstractions.
  • Java based Query, Criteria, and Update DSLs.
  • Automatic implementation of Repository interfaces including support for custom finder methods.
  • QueryDSL integration to support type-safe queries.
  • Cross-store persistence - support for JPA Entities with fields transparently persisted/retrieved using MongoDB.
  • GeoSpatial integration.
  • Map-Reduce integration.
  • JMX administration and monitoring.
  • CDI support for repositories.
  • GridFS support.

Online Resources:

Frequently Asked Questions

3281 questions
1
vote
1 answer

Mongodb Filters between Date in Java

Please help, I need to filter between dates using java mongodb driver below is is my Filtering operation however, its failed to select between the date FindIterable documents = collection .find(Filters.and("started",…
1
vote
0 answers

QueryDSL with Spring Data MongoDB - contains all

I wanted to achieve something similar to contains all, but I couldn't find any support for mongodb - $all, so I tried to do this by hand. My entity has a simple set of tags - Set. val taskEntity = QTaskEntity.taskEntity val where =…
Shadov
  • 5,421
  • 2
  • 19
  • 38
1
vote
1 answer

How to Flatten dynamic field with parent document - Spring data Mongo DB

In my Spring boot project have a Document like so: @Document(collection="AuditTable") public class AuditTable { @Id private String id; private Map properties; where properties is a dynamic field i.e. it can take in as…
1
vote
0 answers

Spring Data MongoDB Converter not getting registered

I have a setup of multiple MongoDB configuration. Here is the configuration class @Configuration @RequiredArgsConstructor @EnableConfigurationProperties(MongoConfigProperties.class) public class MultipleMongoConfig { private static final Logger…
Shubham
  • 97
  • 1
  • 14
1
vote
3 answers

Building aggregation operation over date using Spring and DateFromString

I have a collection with the following document : { "observation": { "temporalExtent": [ { "dateBeg": ISODate("2002-07-28T20:47:00.000+02:00"), "dateEnd": ISODate("2003-09-13T16:17:00.000+02:00") } ] } } I'm…
charlycou
  • 1,778
  • 13
  • 37
1
vote
1 answer

Spring data conditional projection not working as expected

Basically, I have two fields "totalAmountWithShipping" and "totalAmountPlusShipping" and want to project "totalAmountWithShipping" to a new field called "realTotalAmount" if "totalAmountWithShipping" is greater than 0, and project…
1
vote
0 answers

Idiomatic way to create a variable spring data mongodb Query in Kotlin?

Using Kotlin and spring data mongodb, I'm trying to find the most idiomatic method that can receive nullable parameters (through user defined filters) and create a MongoTemplate Query with the non-null ones (which, in Java, would be a bunch of ifs).…
Tarek
  • 3,080
  • 5
  • 38
  • 54
1
vote
1 answer

How to add Array of Fields to ProjectionOperation with Spring data mongodb

I have this parto of query in mongo that return an array of fields. { $project: { ... result: [ { sumShotsOfOneAttempted: '$sumShotsOfOneAttempted1', sumShotsOfOneFailed: '$sumShotsOfOneFailed1'}, …
1
vote
1 answer

Group by time interval spring-data-mongo

Below is my document structure: { "_id":"5c59c35d8610f702d00e6f70", "stationId":"2", "listenerId":"807", "streamId":"37", "userAgentId":"7", "botDefinitionId":"18", "ipAddress":"50.116.14.48", …
Sixthpoint
  • 1,161
  • 3
  • 11
  • 34
1
vote
1 answer

Spring Transactional not rolling back on exception

I have the following two method to store the single user and multiple users in mongodb using Spring data JPA's MongoRepository. If any exception happened in the method it is not rollbacking. I can able to find the data in…
1
vote
1 answer

mongodb differences between clients

I'm very confused and I can't seem to find any explanations on the web. windowStart is a ISODate in my documents. When using the mongodb-java-driver (via the mongoTemplate in Spring) the following works fine... {windowStart : {$lt : new…
paul
  • 494
  • 6
  • 17
1
vote
1 answer

How to group the dates based on month using Spring-data-mongodb and get the latest value of each month?

Below is a part of my json structure : { "dateOfCalculation" : ISODate("2018-08-13T06:02:48.587Z"), "value" : 6.0 }, { "dateOfCalculation" : ISODate("2018-08-13T06:04:38.294Z"), "value" : 8.0 }, { …
SnS
  • 175
  • 2
  • 16
1
vote
1 answer

Find an element's highest level ancestor without having bi-directional reference

I'm using MongoDB to store subcategories in categories, and items in the subcategories. I'd like to retrieve the main category by an item. How can I do that in Spring Data the easiest way without having a bi-directional reference? class Category { …
OCPi
  • 316
  • 1
  • 5
  • 16
1
vote
1 answer

Overloading in Flux mapping?

I want to stream events multiple events, all inherited from the same base type, from a mongoDB, using the spring ReactiveMongoRepository. Next I want to have them all differently handled and thus defined several overloads of a handle method, all for…
PeMa
  • 1,559
  • 18
  • 44
1
vote
0 answers

Unknown Top level operator $exists

This is my query: var que=Query(Criteria.where("name").exists(true).`isEqualTo`("Technographics")) mongoTemplate.exists(que,"collectionname"); It throws UncategorizedMongoDbException: Command failed with error 2: 'unknown top level operator:…
jss
  • 199
  • 2
  • 13