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
0 answers

Naming a Query Methods for MongoRepository with multiple conditions in SpringBoot

According to the documentation, I'm trying to get a working name for a method of a Spring MongoRepository that have to meet two different conditions. In plain words, the query sounds like: "look up for a determinate object by his id and it is one of…
marco
  • 3,193
  • 4
  • 28
  • 51
1
vote
1 answer

How to build a search endpoint in spring data MongoRepository

I'm trying to access the mongodb data layer using spring data MongoRepository. So in here im able do the basic CRUD operations using the repository endpoint but failed to do the custom search. Model class : @Document(collection = "merchant") public…
1
vote
1 answer

Spring Data Models - Abstract Base Classes With Lombok?

I have a design question around models in Spring Data (and in my specific case Spring Data Mongo). My requirements: I want to enforce that all aggregate roots use a String as the datatype for ID. I want to force IDs that are empty string or…
Tyler Van Gorder
  • 453
  • 6
  • 14
1
vote
1 answer

Increase value of a field inside an array of element

I have documents that has the following structure in my collection: { "_id": "1234566780", "arrayField": [ { "id": "1", "count": 3 }, { "id": "2", "count": 5 } ] } I want to have a…
Manuelarte
  • 1,658
  • 2
  • 28
  • 47
1
vote
0 answers

Spring Data Mongo - Issue using Aggregation.group() and Aggregation.facet() on array field

I'm using the following aggregation pipepline and I'm having a weird behaviour in Spring Data Mongodb. The Aggregation is going well until the facet stage that throws Invalid reference 'producer.fundings.type'! exception. Fields…
1
vote
2 answers

Why I see lombok imports in decompiled class

When I open and decompile a class from spring-data-mongo@2.1.3 in IntelliJ, I see import lombok.NonNull, but I do not see any lombok transient dependency in my project. Now, this makes sense because lombok is set as optional dependency in…
1
vote
1 answer

Spring Data mongodb: 'year' must evaluate to an integer

I've built this aggregation: ProjectionOperation projectStage = Aggregation .project("application", "uploadedRefs", "uploadedKb", "downloadedDocs", "downloadedKb") .and(DateOperators.Year.yearOf("timestamp")).as("year") …
Jordi
  • 20,868
  • 39
  • 149
  • 333
1
vote
0 answers

Springboot : How do i perform complex queries in MongoDB like getting a list of a property of an Object and not the whole object in Mongo DB

I have a Springboot app which uses contains 2 Entities, User and Friend Request. The user Entity looks like this: public class User{ @Id private BigInteger id; private String firstName; private String lastName; private…
Oto-obong Eshiett
  • 1,459
  • 3
  • 18
  • 33
1
vote
4 answers

Fongo 2.1.0 not working with Mongo java driver 3.2.8

I am trying to upgrade mongodb to 4.x from 3.x since we need to have transaction support in mongodb, and also using fongo for junits. I have modified version for below given dependencies…
Bhagwati Malav
  • 3,349
  • 2
  • 20
  • 33
1
vote
1 answer

Spring Data MongoDb bean xml configuration for repository interface

I have an existing spring application using xml configuration. Now, I will be using spring-data-mongodb to connect it to a Mongo database. My repository/dao are all interfaces like: public interface CustomerDao extends MongoRepository
Borgy Manotoy
  • 1,960
  • 5
  • 27
  • 42
1
vote
2 answers

Custom query regex MongoDB + Spring Data

I'm trying to write a "startsWith" query in Spring Data, using MongoDB. If I write this in Mongo shell, it works, lists every e-mail address starting with letter x or X (case insensitive): db.user.find({email:/^x/i}) However, this…
Peter
  • 323
  • 1
  • 16
  • 46
1
vote
1 answer

How to search through a list of objects nested inside an array with Spring data MongoDB?

I have got a collection of documents and each documents contains a nested array of objects. { "id": "309324739", "debters": [ { "user": { "name": "John Doe", "internal": true }, "debt": 1463, }, { …
ignite-me
  • 738
  • 3
  • 14
  • 33
1
vote
0 answers

Adding options in MongoDB Regex Expression in Spring Data

I am trying to do automated Regex expression match with Spring MongoDB Data. This is what I have tried, but Spring doesn't recognize the options I am giving. I am trying to give the option 'i' to make the matching case insensitive. But doesn't seem…
Caranthir
  • 21
  • 4
1
vote
1 answer

How to get the specified object fields from array in spring mongo using MongoRepository interface

Json Object { "_id" : ObjectId("5c07afde9bc2e9ab1dfb6c01"), "rates" : [ { "day" : "Mon", "start" : "0900", "end" : "1800", "found " : "active" }, { "day" :…
Sriram
  • 101
  • 9
1
vote
0 answers

Mapping exception from Java 8 LocalDateTime to MongoDB

I appear to be having a problem writing a DB entity with a java.time.LocalDateTime field to a MongoDB table. Everything I've read seems to say that this should not be a problem circa end-of-2014, but I'm still getting it for some…
Ertai87
  • 1,156
  • 1
  • 15
  • 26