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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
12 views

Issue with @Aggregation Annotation in Spring Data MongoDB Repository

I am encountering an issue with the @Aggregation annotation in a Spring Data MongoDB repository in my Spring Boot application. While the @Query annotation works as expected, using @Aggregation results ...
Richard N's user avatar
0 votes
0 answers
7 views

@Version in MongoDB Limit

I am using @Version to handle optimist lock And I have a question, what happened when it is 2147483647, or max number expression in Long? In the most example @Version is used with Long and in MongoDB ...
Lucas da Silva Lima's user avatar
0 votes
0 answers
31 views

Better way to store mongo collections details as Java constants

public class MongoDBConstants { // Define the collection names public static final String USER_COLLECTION = "users"; public static final String PRODUCT_COLLECTION = "...
Bharath Tej Chinimilli's user avatar
0 votes
1 answer
24 views

Spring data mongodb repository - How to exclude null/blank fields from query using the @Query annotation?

I'm using the Spring-data-mongodb repository framework in my Spring Boot project. I have an API where users can specify 1+ query parameters when searching for an object, and I would like to convert ...
takanuva15's user avatar
  • 1,344
0 votes
1 answer
29 views

How to set maxTimeMS on Spring Data MongoDb Repository methods

Spring Data MongoDB Repository provides a lot of useful ways to generate queries, e.g. derived queries, and CRUD operations. For example: public interface UserMongoRepository extends MongoRepository&...
awgtek's user avatar
  • 1,592
0 votes
0 answers
32 views

Spring Boot 3.2 - Multicluster MongoDB Connection with NodePort

I have a Spring Boot 3.2 (RC2) based application that connects to MongoDB. My MongoDB is a ReplicaSet deployed on two Kubernetes clusters: three nodes on cluster A (and one arbiter) three nodes on ...
fuerteVentura22's user avatar
0 votes
0 answers
10 views

Optimistic @Version is increased when update fails due MongoSocketOpenException

I would like to have working retry when Mongo is temporary unavailable. I simply down Mongo and start process with mongoTemplate.save() in loop with sleep. When I up Mongo, save() is rejected due ...
michaldo's user avatar
  • 4,244
0 votes
2 answers
61 views

Spring boot mongodb : Updating multiple records with custom value using updateMulti

I have a list of records. Each record needs to have 2 fields: temp(temperature in Celcius) and temp_F(temperature in Fahrenheit). temp field is available in mostly all records. But temp_F is missing ...
Kanhaiya's user avatar
  • 374
0 votes
0 answers
103 views

Mongo bean exception while connecting to MongoDb with Spring boot

I am new at using MongoDb and I am trying to make a simple connection usage to test it locally. The error I am getting is this: org.springframework.beans.factory.UnsatisfiedDependencyException: Error ...
Luca Ferretti's user avatar
0 votes
0 answers
13 views

Mongodb text Search with Search words with Negated Term

This is how the logic should work Search names: Ram, David, Lakshman Negated names: Ram Search has the following names Ram Kumar Ram Lakshman David Kumar The Search result should be : Ram Lakshman ...
user3437378's user avatar
0 votes
1 answer
47 views

Missing some records and found duplicate records wrote to output .csv file

I am using MonoItemReader and writing my .csv file but I found some duplicated records and missing records from my .csv files My .csv output file I set BatchApplication.java right this @...
Same's user avatar
  • 5
0 votes
0 answers
21 views

Spring Data MongoDB - wrong collection name with inheritance

I'm developing an application with Spring Data MongoDB. I use a base entity that serves as a superclass of all entities. Each entity therefore inherits from the base entity and has a @Document ...
Timer's user avatar
  • 13
0 votes
0 answers
22 views

ReactiveMongoTemplate-longer response time with spring boot 3.0

After upgrade of spring boot, spring-data-mongodb, spring-boot-starter-data-mongodb-reactive I see that time the following method increased. Could you give me any clue why is that? Old versions: ...
A.Sidor's user avatar
  • 267
0 votes
1 answer
46 views

Any functionality in a MongoDB Aggregation like a simple "regex replace"?

I'm trying to create a step in a MongoDB aggregation pipeline which will replace the value of a full Social Security Number (like "123-45-6789") with a masked value, preserving the last four ...
rook218's user avatar
  • 650
0 votes
1 answer
65 views

Optimize mongo $in query

I've a mongo collection having around 550,000 documents. Document has an array field path on which i have a below query in my java code. This field is indexed. Problem is ids in below query can go up ...
Tech_Dev's user avatar
0 votes
1 answer
33 views

Could not autowire. No beans of 'MongoOperations' type found. Error fix?

` code Error ... Appication Property How to fix this error? How to create Bean class I already configured Mongodb in Property file... Springboot and mongodb dependency already added i already checked ...
Kaligu Jayanath's user avatar
0 votes
1 answer
33 views

Parse out numbers from multiple String fields, add them to a new field in MongoDB aggregation pipeline?

I am trying to come up with a way to parse out the "numbers" in three different fields of type string, convert them to true number types, and add them together into a new field. I have to do ...
rook218's user avatar
  • 650
0 votes
0 answers
31 views

Testing MongoRepository with @DataMongoTest end up in TimeOut

I have a simple MongoRepository : @Repository public interface HistoryRepository extends MongoRepository<HistoryWrapper, String> with two method that I want to test, using @DataMongoTest. I ...
Romain Huber's user avatar
0 votes
1 answer
73 views

How to add a custom primary key in MongoDB document using Spring Data Mongo

I have a MongoDB entity as below. public class Test { @Id private String id; private String name; private String age; } Now, instead of "id", which creates a primary key "_id" ...
Pushpak's user avatar
  • 147
0 votes
0 answers
13 views

how to know the collection name form a given mongo repository

I'm writing a service class which for most parts calls a FieldRepository<Field, String> for database transactions. We have one specific case where we have to pass a dynamically generate ...
Anadi Misra's user avatar
  • 1,979
0 votes
1 answer
53 views

How to read all documents of mongo collection using Spring Batch?

I have to read an entire collection from MongoDB without filters during spring batch. I have created a class XyzMongoItemReader that extends MongoItemReader on XyzMongoItemReader constructor I'm ...
Paul Marcelin Bejan's user avatar
1 vote
0 answers
28 views

Why doesn't Spring Data MongoDB create a time series collection during direct insertion with @TimeSeries annotation?

I'm using Spring Data MongoDB to interact with a MongoDB database. In my application, I have a Test class annotated as a time series collection using the @TimeSeries annotation as follows: TimeSeries( ...
Yashasvi Raj Pant's user avatar
0 votes
1 answer
22 views

How to save complex type property as String in a Spring Data MongoDB entity

In my Spring Data MongoDB project I have a following POJO: @Document(collection = "my_entity") public class MyEntity { private MyProperty myProperty; } where MyProperty: ...
Nemo's user avatar
  • 145
0 votes
0 answers
52 views

MongoDB Command failed with error 91(shutDownInProgress)

We have mongo cluster which is a 3 node replicaset and we connect the cluster using Spring boot app. This cluster have a daily maintenance window of 20-30 sec during which one of the node goes down ...
Smith's user avatar
  • 151
0 votes
0 answers
14 views

how to use spring data mongo in a springboot using aggregation fraimwork

i have created a mongo query as follows db.organizers.aggregate([ {$lookup: { from: "projects", localField: "_id", foreignField: "created_by", ...
Saudip Ghosh's user avatar
0 votes
0 answers
27 views

MongoDB $aggregate $push operation in Java

I have mongo aggregate query as below: { $group: { _id: {applicationNumber: "$applicationNumber"}, recordTypes: { $push: "$allRecords.coreRecord.recordType"} } } I ...
Souvik Adhikary's user avatar
0 votes
0 answers
19 views

SpringData mongoDB API for Aggregation $map $mergeObjects $filter

Following is my Native MongoDB query and I try to migrate the SpringData Mongo API equivalent. I am getting struck on using $map $mergeObjects $filter in $project in SpringData Mongo API. Appreciate ...
pgermano's user avatar
1 vote
1 answer
142 views

Spring data MongoDB (aggregation)

Let's consider the following documents: country{id="1", name="France", cities=[{detail="new_city"}, {from="Paris"}, {from="Lyon"} ]} country{id="...
Adam D's user avatar
  • 47
0 votes
1 answer
26 views

Criteria problem with $in operator in some cases (Kotlin)

The following query does not return any results: val names = mutableListOf("toto") Criteria().orOperator( mutableListOf( Criteria("fieldA.name").`in`(names), ...
Val's user avatar
  • 15
1 vote
1 answer
43 views

In Spring Data MongoDB, is there a way to upsert a document when using @Update with a findAnd...ById method?

Note: example is using Spring Data MongoDB in Kotlin leveraging update methods as described at https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongodb.repositories.queries....
Matthew Adams's user avatar
0 votes
1 answer
28 views

spring-data-mongodb dependency for @Aggregation annotation for aggregation pipeline

import org.springframework.data.mongodb.repository.Aggregation; Following import is not resolved for <dependency> <groupId>org.springframework.data</groupId> <artifactId>...
Sameer Makwana's user avatar
0 votes
0 answers
18 views

Intermittent mongodb socket timeout error

I keep getting below error intermittently com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message at com.mongodb.internal.connection.InternalStreamConnection....
Teegen's user avatar
  • 3
0 votes
0 answers
44 views

Spring: "Authentication object cannot be null" when creating MongoDB index programmatically

I'm trying to create an index (@CompoundIndex to be precise) like described in 'Example 186' in https://docs.spring.io/spring-data/mongodb/docs/3.4.11/reference/html/#mapping.index-creation. This is ...
Sebastian Forza's user avatar
0 votes
1 answer
33 views

Spring data mongodb read only property keys are getting removed from database

I have annotated some keys in entity pojo with @ReadOnlyProperty because I don't want to set those field from working application because Those fields will be set/updated from different application. @...
gss2408's user avatar
  • 13
0 votes
1 answer
35 views

Distinct on multiple columns in MongoDb using Spring data Mongo aggregation API

I am new to Mongo db and aggregation query. I want to perform distinct on 2 fields i.e. userId and user in mongo db collection with name "userDetails". I am able to execute below query and ...
user2068260's user avatar
-1 votes
1 answer
94 views

MongoSocketException : nodename nor servname provided, or not known

I am trying to connect my spring boot service to a mongo cluster. Below is my application.yml configuration for mongo uri: mongodb://user:paswd@ip1:27017,ip2:27017,ip3:27017/dbname?authSource=...
jatin's user avatar
  • 11
0 votes
0 answers
33 views

@DocumentReference behavior for fields sent to a pub/sub topic

I am working with Spring Data MongoDB and I am using @DocumentReference for referencing between documents. And I want to send an object to a pub/sub topic with Google pub/sub. Example for Account ...
Moh-Dev's user avatar
0 votes
1 answer
229 views

Upgrade of Mongodb Driver to 4.7.0 is not working in spring boot 2.7.15

I am trying to upgrade the MongoDB driver to 4.7.0 from 4.6.1 but the driver is not getting upgrade to MongoDb driver 4.7.0. Have tried with springboot 2.7.15 version but the driver is not getting ...
Rose's user avatar
  • 111
1 vote
0 answers
27 views

Spring Data Mongo Aggregation Pipeline fails

I am experimenting with the aggregation pipelines with spring integration. I have the following data model: @Document data class Team( val teamName: String, val projects: MutableSet<String&...
Christian's user avatar
  • 830
0 votes
0 answers
70 views

Spring @Transactional is working for self calls in some services but not for all services with same scenario, why?

I have two services as given below, and both has public methods with @Transactional annotation which is invoked via a self call. @Service public class ShopManager { @Autowired ShopRepository ...
vinodpthmn's user avatar
  • 1,062
0 votes
1 answer
34 views

How can I insert to MongoDB a nested JSON lines

I have an Event Entity for MongoDB like this: @Getter @Setter @Document(collection = "events") public class Event { @Id private String id; private String event; private ...
egepancaroglu's user avatar
0 votes
1 answer
43 views

MongoDb query array with date, filter per date range

I have a document like this: dataRanges: [ { "name":"dataRange_0", "range" : [ { "dateStart": "2000-01-01T00:00:00Z", ...
Samuel's user avatar
  • 1
0 votes
1 answer
131 views

How to update index in MongoDb when using Spring?

Let say I have class annotated with the following @Data @CompoundIndex( name = "unique_name_with_age", def = "{ 'firstName':1 , 'lastName':1 }", unique = true) @...
Finlay Weber's user avatar
  • 3,141
0 votes
2 answers
40 views

Java spring-mongo-data Mongodb query for group and projection logic

I have below 3 sample records: { "_id" : "0cc5c468-2105-11ee-ad68-15d467e62by4d", "storeId" : "3070", "paymentType" : "cash&...
jarvo69's user avatar
  • 8,067
0 votes
1 answer
42 views

MongoDB cluster with SpringBoot WebFlux duplicates records

I use mongodb cluster with 3 replicas (1 primary and 2 slaves). Mongo version 5.0.4. Also SpringBoot WebFlux application with reactive mongodb driver. I often see duplications in database when I save ...
Virkom's user avatar
  • 373
0 votes
1 answer
138 views

Getting Stackoverflow error while upgrading from spring boot 2.7 to 3.0.8

I am upgrading SB version from 2.7.12 to 3.0.8 and while upgrading i am getting the following error - java.lang.StackOverflowError: null at org.springframework.data.mapping.model....
R0512S's user avatar
  • 53
1 vote
1 answer
20 views

Spring Boot does not return any data from query for composite primary key

I have a list classes ProductId and Product. I also have a ProductRepository for the Product class. The ProductId is a composite primary key. How can I write a criteria query for a list of composite ...
BreenDeen's user avatar
  • 647
3 votes
1 answer
47 views

How to lookup in the same document under a collection in MongoDB

I am having below document in MongoDB [UPDATE : Shortened the document] { "sections": [ { "_id": { "$oid": "64cbeb62b669cd29a5719a8f" }...
Pushpak's user avatar
  • 147
0 votes
0 answers
50 views

Slow mongodb query for just 200 simple records in collection , query optimization

I have mongodb collection called "product" which contains following type of documents: { "_id" : "64a1583ab9ec356358be7853", "productId" : Long("7&...
jarvo69's user avatar
  • 8,067
1 vote
1 answer
27 views

How to update value in below document in MongoDB

I have below document in MongoDB in which I want to update the 'value' field given the attribute say '64ca0aaa731a2a7284c24c5f here. { "id": "64ca0aaa731a2a7284c24c57", "...
Pushpak's user avatar
  • 147

1
2 3 4 5
66