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

2843 questions
111
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 have been starting by using the MongoRepository but struggled with complex queries to find examples or to actually understand the Syntax. I'm…
Christopher Armstrong
  • 2,987
  • 5
  • 29
  • 38
66
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"); …
54
votes
10 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,097
  • 2
  • 10
  • 22
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
37
votes
12 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,589
  • 2
  • 27
  • 43
37
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__
  • 471
  • 1
  • 4
  • 10
36
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…
30
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
  • 301
  • 1
  • 3
  • 4
29
votes
3 answers

"invalid hexadecimal representation" for spring mongo data repository interface

I have a repository interface as follows: public interface ExcursionAttendeeRepository extends MongoRepository { ExcursionAttendee findByWorkflowItemId(String workflowItemId); @Query("{ 'excursionEvent._id' : {…
Susitha Ravinda Senarath
  • 1,452
  • 2
  • 20
  • 43
29
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…
29
votes
2 answers

How to return raw JSON directly from a mongodb query in Java?

I have the following code: @RequestMapping(value = "/envinfo", method = RequestMethod.GET) @ResponseBody public Map getEnvInfo() { BasicQuery basicQuery = new BasicQuery("{_id:'51a29f6413dc992c24e0283e'}", "{'envinfo':1, '_id': false }"); …
pdeva
  • 36,445
  • 42
  • 122
  • 154
27
votes
2 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
  • 20,249
  • 33
  • 132
  • 224
27
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,466
  • 5
  • 26
  • 44
26
votes
6 answers

Spring-data-mongodb connect to multiple databases in one Mongo instance

I am using the latest spring-data-mongodb (1.1.0.M2) and the latest Mongo Driver (2.9.0-RC1). I have a situation where I have multiple clients connecting to my application and I want to give each one their own "schema/database" in the same Mongo…
sbzoom
  • 2,977
  • 4
  • 25
  • 31
23
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
  • 483
  • 1
  • 6
  • 17
1
2 3
99 100