414 questions
0
votes
0
answers
64
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....
0
votes
1
answer
78
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
184
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
279
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
1
answer
221
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
612
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
1
answer
128
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
344
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:
...
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": [
{
...
0
votes
1
answer
311
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 ...
0
votes
1
answer
634
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 ...
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 (...
2
votes
0
answers
811
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....
0
votes
1
answer
131
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
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&...
0
votes
1
answer
203
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 : {$...
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
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
2
answers
643
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....
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
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;
}
...
0
votes
1
answer
37
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
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
2
answers
848
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 {
...
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",
...