Questions tagged [spring-mongodb]

Do not use this. Use [spring-data-mongodb] instead.

Do not use this. Use instead.

422 questions
2
votes
2 answers

MongoDB and Spring Boot - Best way to update a Document?

I have the following Java POJO in my spring boot application: public class Round { private ObjectId _id; @NotEmpty @Getter @Setter @Accessors(fluent = true) @JsonProperty("userId") …
java12399900
  • 1,485
  • 7
  • 26
  • 56
2
votes
1 answer

Error when save Object - Optimistic lock exception on saving entity

I just doing simple transactions like : findByVariable(String variable); manipulate the data, then save(data); but i got Exception like this org.springframework.dao.OptimisticLockingFailureException: Optimistic lock exception on saving entity:…
donny
  • 439
  • 5
  • 11
2
votes
1 answer

How to make `org.mongodb.driver.cluster` use embedded mongodb within spring boot?

Trying to use embedded mongodb for my spring local profile. Here is the configuration for MongoTemplate @Configuration @Profile("local") public class LocalMongoConfig { private static final String MONGO_DB_URL = "localhost"; private static…
Channa
  • 3,267
  • 7
  • 41
  • 67
2
votes
0 answers

how to add mongodb replica Set in spring boot project

i am new to mongodb repleca set spring boot 2.2.2 mongo db driver 3.12.1 spring.data.mongodb.uri=mongodb://user:pass@server1:27017,server2:27017,server3:27017/DB?replicaSet=‌mongodb_rs always getting the following error while fetching data from…
2
votes
0 answers

Spring Data Reactive Mongo Template: MongoDB cursor

What is the recommended way to iterate over a large result with reactive mongo template? I can't find a reactive alternative for the blocking MongoTemplate::stream() operation, which uses MongoDB cursor (and works perfectly well). When I do the most…
2
votes
0 answers

Mongodb - com.mongodb.MongoSocketReadException: Prematurely reached end of stream

I'm getting this error on connect: com.mongodb.MongoSocketReadException: Prematurely reached end of stream I have looked at the other SO answers and they do not help. I can connect from MongoDB compass with LDAP authentication, the same keys that…
mikeb
  • 10,578
  • 7
  • 62
  • 120
2
votes
0 answers

Spring-mongodb query does not fetch results for LocalDate argument

I have a repository method like this @Query({'date': ?0}) public List findForDate(LocalDate date); and I am using it like this repository.findForDate(LocalDate.now()); because I want to fetch my current log entries. Repo returns empty…
pokemzok
  • 1,659
  • 1
  • 19
  • 29
2
votes
1 answer

Memory leak with Spring MongoDB stream?

The code below causes presumably memory leak: public int reregister(ReregisterDTO reregisterDTO) { AtomicInteger count = new AtomicInteger(0); StreamUtils.createStreamFromIterator( mongoTemplate …
Cmyker
  • 2,318
  • 1
  • 26
  • 29
2
votes
1 answer

How to cancel delete using AbstractMongoEventListener?

Can I cancel delete event using onBeforeDelete method of MongoGenreCancelDeleteEventsListener? If yes then how? @Component public class MongoGenreCancelDeleteEventsListener extends AbstractMongoEventListener { private final BookRepository…
Ekaterina
  • 1,642
  • 3
  • 19
  • 36
2
votes
4 answers

SpringBoot: Unsatisfied dependency NoSuchBeanDefinitionException, expected at least 1 bean which qualifies as autowire candidate

I am making a very silly mistake but not able to figure out how to fix. I have a simple SpringBoot app using profiles, which connect to MongoDb. My pom.xml dependencies: org.springframework.boot
TechiRik
  • 1,893
  • 6
  • 27
  • 37
2
votes
2 answers

How to use $objectToArray in SpringMongo?

In the following query, I'm trying to use $objectToArray mongo aggregated function in a SgringMongo. Can someone help me, please? I couldn't find any way to convert it to a SpringMongo query db.getCollection('application').aggregate([ …
2
votes
1 answer

Caused by: com.mongodb.MongoWriteException: E11000 duplicate key error collection: Blog.Posts index: id dup key: { : null }

I try to load initial json documents into mongodb database with spring boot. First, These are mongodb documents schema. @Document(collection="Posts") public class Post { @Id private String _id; @Indexed(unique = true) private…
Joseph Hwang
  • 1,337
  • 3
  • 38
  • 67
2
votes
0 answers

Spring Data MongoDB Unique Embedded Fields

So, I have one @Document class which has a embedded pojo field which I want it to be unique for the document based on a key in the pojo class. I tried using @CompoundIndex & @Indexed to mark it as unique but it doesn't seem to work. @Document public…
Deepak
  • 171
  • 1
  • 12
2
votes
0 answers

MongoDB native query with Aggreagtion to query in Java

I have native Mongo query [ { $match: { createdById: "5c3cac81989a8469d435f3b2" } }, { $group: { _id: "$uID", latest: { $max: "$latest" }, createdById: { $first:…
2
votes
2 answers

Lombok, Spring mongodb and jackson Constructor problem

I am using Spring Boot and lombok in my project and encounter some issues with it. My class looks like this: import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import…
Thomas
  • 6,325
  • 4
  • 30
  • 65