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
135
votes
3 answers

What's the difference between Spring Data's MongoTemplate and MongoRepository?

I need to write an application with which I can do complex queries using spring-data and MongoDB. I started using the MongoRepository but struggled with complex queries to find examples or understand the Syntax. I'm talking about queries like…
Christopher Armstrong
  • 3,477
  • 6
  • 34
  • 40
99
votes
11 answers

MongoDB Full and Partial Text Search

Env: MongoDB (3.2.0) with Mongoose Collection: users Text Index creation: BasicDBObject keys = new BasicDBObject(); keys.put("name","text"); BasicDBObject options = new BasicDBObject(); options.put("name", "userTextSearch"); …
76
votes
11 answers

MongoDB - Query on the last element of an array?

I know that MongoDB supports the syntax find{array.0.field:"value"}, but I specifically want to do this for the last element in the array, which means I don't know the index. Is there some kind of operator for this, or am I out of luck? EDIT: To…
Joseph Blair
  • 1,385
  • 2
  • 12
  • 25
53
votes
6 answers

How to disable spring-data-mongodb autoconfiguration in spring-boot

Has anyone tried disabling autoconfiguration for mongodb in spring-boot? I am trying out spring-boot with spring-data-mongodb; Using java based configuration; Using spring-boot 1.2.1.RELEASE, I import spring-boot-starter-web and its' parent pom for…
im__
  • 677
  • 1
  • 5
  • 11
47
votes
13 answers

MongoDB-CR Authentication failed

I am getting following error while authenticating user : purchase_user@purchase failed. MongoDB-CR Authentication failed. Missing credentials in user document when I access webservice through browser. But I am able to authenticate purchase_user from…
ashwini
  • 601
  • 1
  • 6
  • 9
44
votes
13 answers

Spring data MongoDb: MappingMongoConverter remove _class

The default MappingMongoConverter adds a custom type key ("_class") to each object in the database. So, if I create a Person: package my.dto; public class Person { String name; public Person(String name) { this.name = name; …
Yuriy Nemtsov
  • 3,869
  • 4
  • 30
  • 44
41
votes
3 answers

What's the difference between Spring Data MongoDB and Hibernate OGM for MongoDB?

I have not used Spring Data before but I've used Hibernate ORM a number of times for MySQL based application. I just don't understand which framework to choose between the two for a MongoDB based application. I've tried searching for the answer but…
user794783
  • 3,619
  • 7
  • 36
  • 58
40
votes
10 answers

Exception in monitor thread while connecting to server localhost:27017 while accessing MongoDB with Java

I have the following exception when running Java app for MongoDB: [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017 while accessing MongoDB with Java Call stack is…
Dims
  • 47,675
  • 117
  • 331
  • 600
36
votes
3 answers

Mongo how to $lookup with DBRef

I have a trouble(/(ㄒoㄒ)/~~). Suppose that collection A is { "_id" : ObjectId("582abcd85d2dfa67f44127e1"), "bid" : [ DBRef("B", ObjectId("582abcd85d2dfa67f44127e0")), DBRef("B", ObjectId("582abcd85d2dfa67f44127e1")) …
Latch Shun
  • 411
  • 1
  • 4
  • 7
36
votes
7 answers

Pagination with mongoTemplate

I have a Query with Pageable: Query query = new Query().with(new PageRequests(page, size)) How can I execute it with MongoTemplate ? I don't see a single method returning Page.
Marcin Wisnicki
  • 4,511
  • 4
  • 35
  • 57
34
votes
6 answers

How to unit test a Spring Boot MongoRepository?

In my Spring Boot web application I use MongoDB to store data. In the application I access the database using interfaces that extend MongoRepository. How do I set up a unit test for such a repository class? What I would like is to start an…
Johanneke
  • 5,443
  • 4
  • 20
  • 33
32
votes
5 answers

How To Configure MongoDb Collection Name For a Class in Spring Data

I have a collection called Products in my MongoDB database, which is represented by the interface IProductPrice in my Java code. The following repository declaration causes Spring Date to look to the collection db.collection:…
Danish
  • 3,708
  • 5
  • 29
  • 48
30
votes
3 answers

How to configure spring-data-mongodb to use a replica set via properties

I am currently writing an application which should use a replica set of MongoDB. It is a Spring Boot based application and the following properties work perfectly fine to connect to one…
incredibleholg
  • 583
  • 1
  • 7
  • 19
30
votes
3 answers

Spring Data MongoDB: how to implement "entity relationships"?

The title of this question is quite contradictory since I'm trying to implement relations in a non-relational database... :) But what I mean is how to define associations between entities in application model classes working with MongoDB. Working…
davioooh
  • 23,742
  • 39
  • 159
  • 250
30
votes
3 answers

How to prevent some HTTP methods from being exported from my MongoRepository?

I'm using spring-data-rest and I have a MongoRepository like this: @RepositoryRestResource interface MyEntityRepository extends MongoRepository { } I would like to allow the GET methods but disable PUT, POST, PATCH and DELETE…
1
2 3
99 100