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

Changing flag in other document when ttl reached in mongo?

I'm having two collections: Devices and Registrations. When I add device then I populate Devices with appropriate entry and create document in Registrations with ttl. After one hour entry expires in Registrations but I would like to additionally…
pixel
  • 24,905
  • 36
  • 149
  • 251
1
vote
2 answers

Mongo Repository spring data giving null pointer on saving list of objects

I have a Spring-Boot with Mongo application where I am trying to persist a list of object. I have a method which parses some json data and creates a list of objects. I then call the save method of MongoRepository to save it all in a go. The…
roger_that
  • 9,493
  • 18
  • 66
  • 102
1
vote
0 answers

Mongobee MongoQueryException: there are no users authenticated

a spring boot application uses mongobee and mongodb, the spring data config is as below: spring: data: mongodb: uri: mongodb://james:xxxxxxx@localhost:27017/?authSource=admin database: shortvideo the mongodb is…
James Hao
  • 765
  • 2
  • 11
  • 40
1
vote
0 answers

Error while reading mongoUri replicatSet config in spring boot

I have mongoUri config set in my properties file like this: spring.data.mongodb.uri=mongodb://user:3YySgdQLEaeFTN2@mongodb-01.uata.lokal:27017,mongodb-02.uata.lokal:27017/dbName And I receive this error: Caused by:…
1
vote
1 answer

Spring Data MongoDB annotation descriptions

I was reading up on Spring Data MongoDB and the documentation Spring Data MongoDB says that since 1.10 Spring Data MongoDB supports @CountQuery, @DeleteQuery and @ExistQuery. But non of the documentations explain what those annotations are for and…
psaw.mora
  • 868
  • 1
  • 7
  • 18
1
vote
1 answer

Error: The method where(String) is undefined while using spring boot mongodb

I have added the mongodb dependencies in my spring boot app however I am getting undefined error on "where" method: ChangeStreamRequest request = ChangeStreamRequest.builder() .collection("person") …
Vishwa Dany
  • 327
  • 2
  • 16
1
vote
1 answer

Spring Reactive with MongoDB fails for more than 1000 records

I have two Spring Boot services, first one reads a file line by line transforming into a flux and makes a POST request: webClient.post() .uri("/foobar/bulk") .contentType(APPLICATION_STREAM_JSON) …
A5300
  • 409
  • 4
  • 18
1
vote
2 answers

Not able to query mongo repository with parameter

I'm trying to query the following object from mongodb [ { "id": "6b3a9814c1990a0578988d9e", "details": { "buyerId": "5bd450ed0307fa0a3a904376", "offerId": "1", "productId": "5b3a9814c1880a0578988d6a", …
Kaigo
  • 1,267
  • 2
  • 14
  • 33
1
vote
1 answer

Mongodb Unable to persist transaction state because the session transaction collection is missing

I'm using Mongodb 4 with spring boot 2.1.0-M4 The follwing code works locally on my computer, but fails at dev environment: @Transactional public void registerNewUser(UserRegistrationForm registrationForm) throws IllegalArgumentException { …
Ben
  • 3,989
  • 9
  • 48
  • 84
1
vote
2 answers

Spring Data MongoDb @Query won't work with more than one $or conditions

I have a strange problem with a simple @Query with spring data and mongodb, the problem is when I use more than one $or condition, it seems that it won't work with 2 or more $or conditions at same time, or I cant put it to work, It only works with…
1
vote
1 answer

MongoDB One-to-Many and Many-to-One relations

I'm trying to optimize my MongoDB collections. This is the example: @Document class Article { @Id private String id; @DBRef(lazy = true) @CascadeSave private List comments; private String title; private String…
1
vote
3 answers

Spring Boot Mongo findById returns null

I have a collection, with documents having a field named _id of type String, not generated manually. I have been trying to get a document using its id. val criteria = Criteria.where("_id").`is`("a2z3e44R") val document =…
Tristan
  • 11
  • 1
  • 3
1
vote
1 answer

MongoDB - find where BinData is equal to UUID value

I try to write application in Java and Spring Data MongoDB. My document looks: @Data @ToString public class SomeDocument { private UUID id; private String name; } Repository: @Repository public interface SomeDocumentMongoRepository extends…
user
  • 4,410
  • 16
  • 57
  • 83
1
vote
1 answer

Cannot use Nested VariableOperators.mapItemsOf in Spring Data MongoDb

I'm forced to use the aggregation framework and the project operation of Spring Data MongoDb. What I'd like to do is creating an array of object as a result of a project operation. Considering this intermediate aggregation result: { "processes":…
1
vote
2 answers

How to limit number of results in ReactiveMongoRepository

I am looking for a way to pass the limit to the mongo query in ReactiveCrudRepository I tried adding "First2" to the method name but I'm still getting all the results. What I'm really looking for is a way to pass the value of the 'limit' to the…
Dmitri
  • 34,780
  • 9
  • 39
  • 55