Questions tagged [spring-mongodb]

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

Do not use this. Use instead.

422 questions
3
votes
2 answers

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", userName: "XYZ User", age: 12 } Collection 2 ("square") { _id:…
3
votes
2 answers

Mongo aggregation vs Java for loop and performance

I have a below mongo document stored { "Field1": "ABC", "Field2": [ { "Field3": "ABC1","Field4": [ {"id": "123" }, { "id" : "234" }, { "id":"345" }] }, { "Field3": "ABC2","Field4": [ {"id": "123" }, { "id" : "234" }, { "id":"345" }] }, …
PrabaharanKathiresan
  • 1,099
  • 2
  • 17
  • 32
3
votes
2 answers

How to import JSON data files to mongodb with Spring Boot?

As you know, when using spring boot jpa module, below codes in application.properties import pre-defined sql data to rdb. spring.datasource.initialization-mode = always spring.datasource.data = classpath:/sql/spring-boot-mysql.sql But when using…
Joseph Hwang
  • 1,337
  • 3
  • 38
  • 67
3
votes
1 answer

Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. state = connected

I am trying simple CRUD on my mongo server and I am getting this one com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is…
user3751481
  • 125
  • 2
  • 10
3
votes
2 answers

MongoTemplate aggregation not mapping the result

I am trying to run aggregation pipeline in a spring boot project using MongoTemplate and aggregation framework. My query executes without any exception. But when I try to call the getMappedResults() on the AggregationResults instance, it always…
greenPadawan
  • 1,511
  • 3
  • 17
  • 30
3
votes
1 answer

Spring WebFlux with MongoDB - throttling SSE clients

I am working on a simple chat service ran by Spring Boot 2.1.1 with WebFlux, Reactor 3.2.3, Mongo 3.8.2 and Netty 4.1.31. Each chat room has 2 collections - messages archive and a capped collection with current events (eg. new message event, user…
3
votes
1 answer

Check MongoDB connection using MongoTemplate in Spring Boot

I am working on Spring Kafka Mongo Integration for insert/update operations and using mongotemplate to perform these actions. I want to know is there any way to check mongodb connection is up/down so that in case my db goes down I want to commit…
user8363477
  • 655
  • 4
  • 14
  • 24
3
votes
0 answers

Spring MongoDB Repositories on multi class collections return all types not the repository one

I would like to store some configuration related classes in the same mongo collection. Thereby I have 2 different objects. @Document(Collection="config") public class Config {...} and @Document(Collection="config") public class ActiveFieldsConfig…
Daniel
  • 41
  • 5
3
votes
2 answers

Mongodb Aggregation : Project an array without the last element

Using aggregation pipeline in spring Data, I have documents with nested arrays, and I want to project an array except the last item of it. for example for each document like : { "_id" : ObjectId("59ce411c2708c97154d13150"), "doc1" : [ …
3
votes
1 answer

MappingException: Ambiguous field mapping detected

Using Spring boot 1.5.6.RELEASE. I have the following mongo document base class: @Document(collection="validation_commercial") public abstract class Tier { @Id private String id; @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) …
PgB
  • 83
  • 2
  • 7
3
votes
0 answers

Getting NestedServletException in Junits of SpringBoot project

I have a SpringBoot project with Mongo DB connection, application is working fine, but Junits are failing with below exception when mongoTemplate.find(query, SchedulerEntity.class) is called in Impl class. Am I missing anything here? I have used…
Naveen
  • 907
  • 2
  • 15
  • 25
3
votes
1 answer

spring mongodb - sort nested collection field

I have nested collection inside a java spring mongodb object. Can I sort the nested collection based on the values it hold? class A { List blist; .. } class B { String date; } So here, I want to sort the blist collection based on the date. Is…
sheikhisham
  • 83
  • 1
  • 2
  • 8
3
votes
1 answer

Spring @ComponentScan annotation doesn't work

I have spring boot application sample with package layout: main: -com.foo Application.java -com.foo.services ItemService.java ItemRepository.java -com.foo.config Configuration.java test: -com.foo.services …
magulla
  • 499
  • 1
  • 9
  • 22
3
votes
0 answers

Spring Mongodb fetch data using DBRef association

I have a retailer class with nested dbref of Address. I would like to fetch retailers based on city which is part of Address class. But I am getting below error. org.springframework.data.mapping.model.MappingException: Invalid path reference…
Debopam
  • 3,198
  • 6
  • 41
  • 72
2
votes
1 answer

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 addUser(Mono user) { return user .flatMap(u -> repo.findByEmail(u.getEmail()) …