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

Spring Data MongoDB applying unique index transitively on parent object

In my Spring MVC application I have the following Mongo entities: @Document(collection = "users") public class UserMongoEntity { @Id private String id; @NotBlank @Email @Indexed(unique = true, sparse = true) private String email; …
Boyan Kushlev
  • 1,043
  • 1
  • 18
  • 35
1
vote
1 answer

Many-to-one relationship in MongoDB

I am new to MongoDB and NoSQL databases and I am trying to learn different kind of thinking that everybody mentions when it comes to NoSQL. I have a typical situation with many-to-one relationship. Please don't tell me that MongoDB is not a…
lot
  • 1,434
  • 18
  • 23
1
vote
1 answer

@DBRef doesn't pull the Data when use Spring Data Mongo

I used the code from : Error creating bean with name 'personRepository': Invocation of init method failed; nested exception is com.mongodb.util.JSONParseException: and now trying to call Person p = personRepository.findByAddresses_City("London…
PAA
  • 1
  • 46
  • 174
  • 282
1
vote
0 answers

Getting " org.springframework.data.mongodb.UncategorizedMongoDbException: 'can't convert from BSON type string to Date' " exception

Below spring data mongo DB aggregation query meant to get available teachers based on who doesn't have 20 hr / 15 hr workload for a week. public List findAvailableTeachersV2(List leanerPlannedSlotList, int hoursPerWeek) { …
1
vote
0 answers

Spring data mongodb collect distinct subcollections - Performance Tuning

[ { "categories":{ "category":[ "sub1", "sub2", "sub3" ], "category2":[ "sub1", "sub2" ] } }, { "categories":{ …
sankar
  • 268
  • 2
  • 15
1
vote
1 answer

Spring data with multiple modules not working

I'm trying to set up a project with two data sources, one is MongoDB and the other is Postgres. I have repositories for each data source in different packages and I annotated my main class as follows: @Import({MongoDBConfiguration.class,…
1
vote
2 answers

Any way I can change in runtime mongo document name

In the project we need to change collection name suffix everyday based on date. So one day collection is named: samples_22032019 and in the next day it is samples_23032019 Everyday I need to change suffix and recompile spring-boot application…
Marcin Kapusta
  • 5,076
  • 3
  • 38
  • 55
1
vote
1 answer

Spring data mongorepository, find by inner object field

I am developing a simple Social network and need help with mongorepository query. I have 2 documents: @Document(collection = "post") public class Post { ........... @DBRef @Field("settings") private Settings…
Volodymyr Zavada
  • 579
  • 2
  • 8
  • 18
1
vote
1 answer

Spring ReactiveMongoRepository bean not generated

I am quite new to Java & Spring and this is my first Kotlin app so my problem could be Layer-8 (me). But I really do not know what I make wrong. According to this tutorial (https://www.baeldung.com/kotlin-mongodb-spring-webflux) this should work. My…
1
vote
0 answers

Spring data mongodb DbRef cache

I have a query that fetches 10k documents and every document has a dbref to another document. This query takes ~5 seconds to run and is unacceptable. During debug and logging i've spotted that mongo driver makes a round trip to database for every…
aleshka-batman
  • 187
  • 1
  • 13
1
vote
0 answers

The request for an image remains suspended with spring webflux functional

i need to give back an image stored in mogodb with gridfs but every time I get the image, the request remains suspended. In particular, this happens with images over 40k. Actually i use spring data mongodb reactive 2.2.0.M2. The code used is the…
1
vote
1 answer

Manipulating Mono and Flux transformation

I'm using Spring 5 webflux with ReactiveMongoRepositories. Suppose I have 2 collections "Race" and "RaceParticipation": Race : { "_id" : "ID", "name" : "Name" } RaceParticipation : { "_id" : "ID", "userId" : "ID", …
Monta
  • 1,136
  • 1
  • 12
  • 28
1
vote
0 answers

java mongodb geonear using query class

I am trying to find the documents which are near to a point without using aggregation.I want use NearQuery or Query class or any other. I tried with following queries but getting exception 1) NearQuery…
1
vote
0 answers

Accents in Criteria Spring Data MongoDB (1.10.9)

How can I get it insensitive to accents: List andCriteria = new ArrayList<>(); if (StringUtils.isNoneBlank(dtoFilter.getNombre())) { andCriteria.add(Criteria.where("nombre").regex(dtoFilter.getNombre(), "i")); } For…
Jose
  • 1,779
  • 4
  • 26
  • 50
1
vote
1 answer

Mongo DB request in Java Spring-data Mongo

I have an array inside of document. { "id" : "id_1", "name" : "name_1"; "additionalData" : [ { "additionalDataId" : "id_1_1", "additionalDataName" : "name_1_1", "longText" : "A long story…
Yan Khonski
  • 12,225
  • 15
  • 76
  • 114