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

MongoDB nested query in Spring Data repository

I have the document User with the following attributes (name, username, password, application) I want to search all the users that are from the same application as one of the users. Example: First I find what application a user belongs (querying by…
Mauro Cruz
  • 105
  • 1
  • 1
  • 8
1
vote
1 answer

Spring mongo slice array in embedded document

The slice method in aggreation for array within an embedded document is not working for me using spring mongo template. Example: Invoice collection: { "reference_number": "aaa111", "historical_data": { "year": 2010, "data": [ { …
1
vote
1 answer

SpringBoot direct MongoRepository to specific MongoTemplate

I have an app with multiple mongo configurations. This is achieved through some @Configuration classes like so public abstract class AbstractMongoConfig { private String database; private String uri; public void setUri(String uri) { …
MichaelB
  • 1,092
  • 2
  • 16
  • 32
1
vote
0 answers

Update document in MongoDB with unique compound index

I have a document in MongoDB with unique compound index. @Document @CompoundIndex(def = "{'field1':1, 'field2':1", unique = true) public class MyClass implements Serializable { @Id private String id; private Field1 field1; private…
Alesto
  • 639
  • 4
  • 13
  • 29
1
vote
1 answer

How can I get one field of subdocument and all _id from its parents accross all levels?

I have following document structure: { clientId: 1001 buildings: [ _id: campus1 rooms: [ { _id: 2001 name: conference }, { _id: 2002 …
1
vote
2 answers

Spring Data MongoDB building dynamic query

Need help to build dynamic MongoDB query. everything inside the "$or" Array is dynamic. db.group.find({ "version" : NumberLong(0), "$or" : [{ "$and" : [ { "object_type" :…
Arun Kumar V
  • 309
  • 3
  • 4
  • 11
1
vote
1 answer

Spring Cloud Stream with RabbitMQ binder, how to apply @Transactional?

I have a Spring Cloud Stream application that receives events from RabbitMQ using the Rabbit Binder. My application can be summarized as this: @Transactional @StreamListener(MySink.SINK_NAME) public void processEvents(Flux events) { //…
Johan
  • 37,479
  • 32
  • 149
  • 237
1
vote
1 answer

Projections in Mongodb not working as intended

By following the official tutorial for projections in spring data mongodb https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#projections will get an java.lang.IllegalArgumentException: Couldn't find PersistentEntity for type…
1
vote
0 answers

How to watch for changes to specific fields in MongoDB change stream with Spring Data Mongodb

According to the documentation of the mongodb changestream, I can watch for updates on specific fields on the collecttion: const changeStream = collection.watch( [{ $match: { $and: [ { "updateDescription.updatedFields.a": { $exists: true…
Konrad Lötzsch
  • 467
  • 7
  • 15
1
vote
0 answers

@Document(collection = "collectionName") not working when extend another class

I am working on a spring boot application with spring data mongoDB. I have a common class which holds all the common properties and my other classes extend it so that I have those common properties in…
Amit Patel
  • 37
  • 1
  • 5
1
vote
2 answers

Thymeleaf form can't handle org.bson.Document type

I have an entity class with fields of type org.bson.Document. These are values that I am not allowed to modify, but when using Spring Data I need to map them in my model class so that after saving the document back to Mongo these values won't be…
fpiechowski
  • 517
  • 1
  • 7
  • 21
1
vote
1 answer

Spring modelling: field as interface

Is there any way to put a field inside a document's model as interface? Example: public class Foo { private String id; private Bar bar; } Where Bar is an interface with multiple implementations. Inside Bar there is a method signature String…
AlexGreg
  • 838
  • 10
  • 22
1
vote
1 answer

How to fetch a data from two collections at a same time in MongoDB?

eg. I have two collections (i.e C1, C2) both collections have same columns (i.e _id, Message, Date) and I want to fetch only 50 documents from C1 and C2 in ascending order of date. I am getting data from one collection only by using following…
1
vote
1 answer

Group aggregation using spring data mongodb

I tried to write a group aggregation query using the year value from a date object as a key, but for some reason I'm getting this exception. org.springframework.data.mapping.PropertyReferenceException: No property year(invoiceDate) Here is the…
user134
  • 391
  • 2
  • 5
  • 15
1
vote
1 answer

Query an Array within projection in Spring Data

Considering this set of data : { "lstLikeUserid" : ["5992dc5725ac203acfa101e6"], "title" : "a title" }, { "lstLikeUserid" : ["6000dc5725ac203acfa101e6"], "title" : "another title" } I want to create a computed field to indicate that a user id…
1 2 3
99
100