415 questions
1
vote
1
answer
140
views
Spring Boot (4.0.0) Cannot Connect to MongoDB in Docker Compose Network
I'm trying to connect my Spring Boot application (using spring-boot-starter-data-mongodb) to a MongoDB instance within a shared Docker network managed by docker-compose.
The connection is failing, and ...
0
votes
0
answers
76
views
Test tries to connect localhost instead of using embedded mongodb by @DataMongoTest
I have spring app which uses mongoRepository. I want to have an integration to test my repository by using @DataMongoTest. For some reason my test tries to connect localhost for mongo and gets timeout....
1
vote
1
answer
93
views
Get both metrics and traces in Mongodb in Spring
I followed the Spring's documentation to see traces in Mongodb by adding the bean
@Bean
MongoClientSettingsBuilderCustomizer mongoMetricsSynchronousContextProvider(ObservationRegistry registry) {
...
0
votes
1
answer
83
views
Spring MongoRepository very slow to return entities
First disclaim: I've already seen these topics
==> Spring MongoRepository very slow to convert POJO
==> performance issue on Spring Data Mongodb
I clearly have a similar problem, but nothing in ...
0
votes
1
answer
380
views
SpringBoot - MongoDb Connection settings not working
I'm trying to set the timeout settings for Mongo connection in my Springboot app but they are not working as intended. I'm not sure if the issue is with the configuration I have or maybe my test is ...
0
votes
1
answer
194
views
What is the role of @Transactional(readOnly = true) in Spring MongoDB
I understand that when using transactions in MongoDB with the WiredTiger storage engine, the isolation level is fixed to snapshot.
If I use @Transactional(readOnly = true), it allows consistent reads ...
0
votes
0
answers
47
views
How to view the complete aggregation statement when using spring data mongodb?
I just started using spring data mongodb aggregation query.
fun findRoot(): MarkdownMongoDocument? {
val aggregation = Aggregation.newAggregation(
MarkdownMongoDocument::class.java,
...
0
votes
0
answers
283
views
Java Mongo DB update Query using aggregation pipeline using $subtract on DateTime field, $match, $project not working
I am using below mongo aggregation pipeline in spring boot java to update document in mongodb. Below is the raw mongo query that works fine when executed directly on mongodb
db.lock.aggregate([
{...
0
votes
0
answers
50
views
Spring Mongo how to do query across different datatbase
I need to migrate from single database to two database,
and my project have a lookup aggregation like
LookupOperation lookupOperation = LookupOperation.newLookup()
.from("race")...
0
votes
1
answer
231
views
Upserting a collection of objects in Mongo in a batch in java using Mongotemplate
I have a list of objects of type MyObject, and I wish to insert an object if its not present in the mongo collection, or update if it does.
MyObject contains multiple fields, but I want to update if ...
0
votes
1
answer
125
views
MongoRepository saveAll() corrupts ID format
I've found some strange behavior of MongoRepository saveAll().
Here's the entity class and repository:
@Document
public class Entity {
@MongoId
private String id;
...
0
votes
1
answer
614
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 ...
0
votes
2
answers
114
views
spring mongo how to pass a variable in native mongo aggergation query
I need to do an aggregation query ,
MatchOperation matchOperation = Aggregation.match(new Criteria("age").is(20));
String lookup = "{$lookup: {from: 'race', localField: 'carId',...
0
votes
1
answer
130
views
Handle Entity annotations for multiple databases (SQL and NoSQL) when only one is active at a time?
I have a school project that needs to support different db at runtime, when only one is selected and is active (a feature to change db after one is selected is not needed).
I've been doing some ...
0
votes
1
answer
111
views
How to use groupby min and rertain all field in Spring Mongo aggregation
I want to get by the fastest speed of each car/carId,
I have problem in getting/retaining all field when using aggregation in spring mongo .
I have check some relatvent in stackoverflow like
mongo ...
0
votes
1
answer
348
views
Spring Data: MongoDB criteria using $toDouble
I have this console query:
db.testcol.find({ $expr: { $lte: [ { $toDouble: "$someField" }, 5 ] } })
I want to write it programmatically using Criteria so I can do the following:
...
1
vote
1
answer
190
views
Spring Boot deleted enum value deserialization from the database
We are working with MongoDB.
We have an object with an attribute which is a set of SubscriptionFeature, where the SubscriptionFeature is an enum.
public class Business {
...
private Set<...
0
votes
1
answer
83
views
Mongo Db - update element by id inside nested arrays - java spring mongo data
Trying to update element by id = 1234567890 and id= 8888888888 and .. (bulk) inside nested array es in the example below
{
"name": "template",
"process": [
{
...
1
vote
1
answer
414
views
Efficiently Update 1 million documents in the mongodb collection
I need to update around 1-1.5 million documents in a Mongodb collection.
Is updateMulti() an efficient way to update the document? I mean will it update the documents in batches internally?
import ...
0
votes
1
answer
312
views
EmbeddedMongoAutoConfiguration throw ArrayIndexOutOfBoundsException and could not initialize MongoTemplate bean
I just add MongoDB configuration to the existing Spring Boot application, some test class has @SpringBootTest annotation, and those classes throw exceptions that says I need to define embedded MongoDB ...
-1
votes
1
answer
892
views
I am trying to convert some Strings I received from my mongodb collection into a java date object. But I can't seem to find a pattern that works
I want to convert values from my mongoDB format into a java Date object(LocalDateTime would also be fine). But I can't find the pattern that does the job.
My 'lastupdated' value inside the mongodb ...
0
votes
1
answer
638
views
MongoDB + Spring: Aggregation with multiple group by and sums
I have my MongoDB query which returns the expected Data but I'm struggling to translate it with Spring (org.springframework.data.mongodb.core.MongoTemplate).
Let's say in my collection A I have this ...
2
votes
1
answer
458
views
Why isn't my user inserted in my mongoDB? spring webFlux reactive REST
I have a Springboot Reactive Web Rest API with a Mongo Database.
My Method in my UserHandler for adding a user looks like this:
public Mono<User> addUser(Mono<User> user) {
return user
...
0
votes
1
answer
179
views
Java driver - BSON filter check if record is deleted?
I am trying to get valid records from mongodb using Spring - mongodb - java driver
my question is around the creation of the Bson filter
I am looking for matching records that match some filter (...
1
vote
1
answer
475
views
How do I allow duplicate key for MongoDB in Spring Boot Project?
This is how my document looks like
@Getter
@Document(collection = "team")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Team extends BaseTimeEntity {
....
private ...
2
votes
0
answers
815
views
Java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.String java.io.File.path accessible error in java 17
I am upgrading my application from Spring Boot version 2.7.3 to 3.0.2 and Java version 8 to 17. My build is successful but during server startup I am getting below exception -
Caused by: org....
1
vote
0
answers
100
views
Spring Data MongoDB: Group Aggregation using $ifNull in _id
I need to translate following MongoDb group aggregation to Java code:
{
$group: {
_id: {"startDate": {$ifNull: ["$startDate", null]}, "name": {$ifNull:...
0
votes
1
answer
135
views
save data to mongodb from redis message
I have problem to save data to mongodb is always null. The data is from redis message publisher that i want to save as a consumer.
I hope get the solution.
Thanks
Service
@Slf4j
@Service
@...
1
vote
1
answer
441
views
Spring, how do I store java.lang.Class type in mongodb
I'm trying to store java.lang.Class in MongoDb using ReactiveCrudRepository, but I got this following errors.
@Document
data class Letter(
...,
val messageType: Class<*>
)
Can't find a codec ...
1
vote
1
answer
3k
views
Spring MongoDB - write a query with multiple $or conditions
For an assignment I have to write a query with multiple OR conditions.
If I had to write it using MongoDB Query Language it would be trivial
{ $and : [
{ $or : [ { "field1" : "value1&...
1
vote
0
answers
81
views
getting object by parameter from nested object mongodb spring data jpa
I have mongodb collection for following documents:
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document
public class Account {
@Id
private String id;
@Indexed(unique=true)
...
0
votes
1
answer
206
views
MongoDB criteria with $trim using MongoTemplate
I'm trying to write a Java code for below MongoDB command using MongoTemplate and Criteria and Trim function on the field value in Mongo collection
db.employees.aggregate([
{
$match : {$...
1
vote
1
answer
1k
views
How to store date in IST format in MongoDb
Unable to store date in IST format in mongo DB
Currently storing date in UTC format during every operations i have to change it into IST format using timezone feature provided by mongo
0
votes
1
answer
2k
views
MongoTemplate - get the connection URI
We are injecting the mongotemplate using the spring config
<mongo:mongo-client id="mongoClient" connection-string="${mongodb.connect-string}">
<mongo:client-settings ...
0
votes
0
answers
290
views
Insert LocalDateTime with MongoTemplate in Azure Cosmos DB
I'm saving a simple java object to Azure Cosmos DB ( mongo API ) from a spring boot application, using mongoTemplate. The insert works, but I'm having some problem with the dates; my object has a ...
0
votes
1
answer
1k
views
Can't connect MongoDB Atlas cluster to a Spring boot app
When trying to just make sure the connect is working, this error arises.
Error that pops up
This is the connect string,
Connection string
This is my aapp.properties,
spring.data.mongodb.uri=mongodb+...
0
votes
1
answer
203
views
force sub classes to initialize a property of the super class
I have an abstract calss Report :
@NoArgsConstructor
@Data
public abstract class Report {
private String surrogateId;
.
.
.
and I need to force all subclasses to fill this surrogateId property. (...
0
votes
2
answers
653
views
How to convert custom Mongo DB update query to Java code
I was finding on the internet how to update all the document field values with lowercase.
I luckily found a query which I modified as per my requirement and it is working correctly.
db.messages....
0
votes
1
answer
230
views
ReactiveMongoRepository insert return converter
Insertion of an entity with an Instant value, using ReactiveMongoRepository:
MyEntity inserted = myReactiveMongoRepository.insert(entity).block();
System.out.println("inserted.getSent() = " +...
1
vote
1
answer
1k
views
MongoDB spring application getAll request not returning all fields
I have created a spring boot application needed for querying and posting to a MongoDB database, I have created a data model that is to be submitted from a website, as well as a service to auto ...
1
vote
1
answer
132
views
Mongo retrieve all values of a specific field including duplicates as list
I have the following data which I am querying on:
[
{
"_id": 1,
"domainName": "test1.com",
"hosting": "hostgator.com",...
1
vote
0
answers
488
views
spring mongodb not saving newly added field
this is my mongo db document
classA {
private String name;
private long elapsedTime; // newly added field
}
@Document
classB extends classA{
private String id;
private String owner;
}
...
1
vote
1
answer
320
views
Having problem with date comparison in @Query [mongo/springboot]
I am trying to create a custom Query annotation in a MongoRepository. Everything is fine except the date comparison. I need to find all items that were created on a specific day, so I give 2 date ...
0
votes
1
answer
38
views
mongo db how to performe two groups
I have the following document :
{
_ids : ...
market : ...
contractorName : ...
field :...
amount : ...
}
and i want to group it first by market then group the result by field (sum of amounts) ...
0
votes
0
answers
98
views
Filter in projection aggregation in SpringMongoDb
I have this aggregation that I want to transform into a Spring MongoDb aggregation.
A document has several named data in a list. But I want to project only 2 datas for a couple of documents with a ...
0
votes
1
answer
128
views
Get likes count and whether user is liked record from MongoDB
I am trying to get count of likes and if user is liked this post in Mongo.
I managed to get this via native query with facets, but problems is how can i map this two fields on my custom java class (...
0
votes
1
answer
671
views
How do you test listCollections in Mongo
I have a spring-boot project, with spring-data-mongo dependency. Everything is working great. I have a service which basically does a listCollections on one of the DB and clears the content of all the ...
0
votes
2
answers
853
views
How to delete a field in all documents of mongodb collection using MongoRepositoty @Query
I have a collection:
public class Person {
private String name;
private Integer age;
}
I want to delete field age in all the documents. So the schema gonna look like that:
public class Person {
...
1
vote
1
answer
607
views
Spring MongoDb Update nested object
Hello I would like use this mongo query in spring to change type fields from string to double:
db.getCollection("data").update(
{
"location.latitude": { $type: 2 },
...
3
votes
2
answers
4k
views
Join two collection in mongodb
I'm new in mongodb. Could you please tell me how to perform join operation in this. I've two collection:
Collection 1 ("user")
{
_id: "d04d53dc-fb88-433e-a1c5-dd41a68d7655",
...