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
2 answers

MognoDB: JSON util is deprecated

Up to now, I've been using this code in order to create a DBObject from a json string: DBObject metadataObject = (DBObject)JSON.parse(jsonString); However, com.mongodb.util.JSON is deprecated, and it's recomended to use BasicDBObject.parse…
Jordi
  • 20,868
  • 39
  • 149
  • 333
1
vote
1 answer

How to Map a Java Entity to Multiple MongoDB Collections in Spring Data?

Currently, we're looking for a solution to save the following User entity into multiple MongoDB collections at the same time (i.e. db_users and on db_users_legacy). Both collections are in the same database. Please don't ask me the reason why I…
Nilanchala
  • 5,891
  • 8
  • 42
  • 72
1
vote
1 answer

Optimal way to duplicate mongo document using spring java

I have a document having the following structure: report { _id : "Jan-2018-0" // (Month-Year-Version) month : "Jan", year : 2018, version : 0, data : [......] } The list of data is really huge. Now my use case is to create a new…
1
vote
1 answer

No converter found capable of converting from type [java.lang.String] to type [java.time.Instant]

We have upgraded springboot 1.5.3 to 2.0. We are getting below exception while reading existing documents. org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type…
doga
  • 471
  • 2
  • 9
  • 20
1
vote
0 answers

$lookup and aggregation in MongoDB and Spring-data

I have this $lookup operation and I have implemented it with Spring. My problem is, that when I am running it in a shell it's working fine but with Spring it's not working. The interesting part is, that when I am adding a $match into Spring (where…
1
vote
1 answer

Cannot create an array of nested object using a project operation

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. For example, considering this intermediate aggregation result: [ …
1
vote
2 answers

Combining mono with flux

I have simple task. I want to add to order products. public Mono addProductsToOrder(String orderId, String[] productIds) { final List productIdsList = Arrays.asList(productIds); final Mono order =…
bkubiak
  • 315
  • 2
  • 3
  • 12
1
vote
1 answer

Convert ObjectId to String in Spring Data

How can I reference two mongodb collections using spring data while the localField is of type ObjectId and foreignField is of type String? ProjectionOperation convertId=Aggregation.project().and("_id").as("agentId"); LookupOperation…
Feras Odeh
  • 9,136
  • 20
  • 77
  • 121
1
vote
1 answer

Mongodb nested collection retrieval

I have a MongoDB collection with the following format: { "_id" : ObjectId("5b6b112d1bbd972848b97df4"), "team" : "Switzerland", "Game" : [ { "City" : "Nizhny Novgorod", …
noopur kharche
  • 59
  • 1
  • 11
1
vote
2 answers

Sort with ignore case in an aggregation

I am trying to sort my result with the case insensitive option. So here is my code: List operations = new ArrayList<>(); Sort.Order sort = ....ignoreCase(); operations.add(new SortOperation(new Sort(sort))); But when I…
Anna
  • 839
  • 2
  • 17
  • 33
1
vote
1 answer

How to use $dateFromString in Spring MongoDB?

In my document, the date field is a string "date": "01/08/2018". How can I convert it to Date object in Spring MongoDB to able to use comparator operators like "gte, lte" to other date object. I tried: project() …
1
vote
0 answers

To delete the documents from a collection if the join condition with some other collection matches?

To delete the documents from a collection if the join condition with some other collection matches? e.g., DELETE FROM TABLE A WHERE A.KEY IN (SELECT KEY FROM TABLE B WHERE STATUS = ‘DELETED’)
1
vote
1 answer

How to project array element field in Spring Data Mongo DB Aggregation

How to project embedded array element field in Spring Data MongoDB Aggregation with the document sample below, I tried: project("customers.id") project("customers.[].id") project("customers.?.id") project("$customers.id") but didn't work. Result…
user123
  • 577
  • 5
  • 23
1
vote
1 answer

SpringDataMongo : searching for a derived class field in mongo collection

Let say we have following model, Base class class Meeting { String title; } First derived class class OfficialMeeting extends Meeting { int numberOfParticipants; String meetingRoomName; } Second derived class class Party extends Meeting { …
1
vote
1 answer

spring data mongodb multiple entity in same collection

I am in a situation where I have to store data belonging to multiple entities in a single collection. But when I query then back, I dont want unwanted records in my result. How can we achieve this using spring? Below is what I have done so far. 1. I…
Sandeep M R
  • 25
  • 1
  • 6
1 2 3
99
100