All Questions

Tagged with
Filter by
Sorted by
Tagged with
129 votes
9 answers
299k views

Spring Boot and how to configure connection details to MongoDB?

Being new to Spring Boot I am wondering on how I can configure connection details for MongoDB. I have tried the normal examples but none covers the connection details. I want to specify the ...
Marco's user avatar
  • 15.6k
54 votes
13 answers
174k views

Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified

I have created a basic spring boot application from SPRING INITIALIZR with the Web, MongoDB and JPA dependencies. When I try to run the spring boot application I am getting the following exception: ...
Subash J's user avatar
  • 2,028
38 votes
4 answers
63k views

Mongo tries to connect automatically to port 27017(localhost)

I am using Spring Rest and Mongo in Maven to make a web service that connects to a server. The problem is that I haven't written any code for Mongo and it is trying to connect to localhost throwing me ...
Haris V's user avatar
  • 403
36 votes
5 answers
75k views

How do you configure Embedded MongDB for integration testing in a Spring Boot application?

I have a fairly simple Spring Boot application which exposes a small REST API and retrieves data from an instance of MongoDB. Queries to the MongoDB instance go through a Spring Data based repository. ...
Jon's user avatar
  • 3,572
36 votes
6 answers
57k views

How to unit test a Spring Boot MongoRepository?

In my Spring Boot web application I use MongoDB to store data. In the application I access the database using interfaces that extend MongoRepository. How do I set up a unit test for such a repository ...
Johanneke's user avatar
  • 5,583
33 votes
6 answers
72k views

Exception authenticating MongoCredential and Uncategorized Mongo Db Exception

I am getting this error socket exception raised by this connection while running my application. INFO 5231 --- [nio-8087-exec-1] org.mongodb.driver.connection: Closed connection [connectionId{...
Sonal's user avatar
  • 375
31 votes
3 answers
68k views

How to configure spring-data-mongodb to use a replica set via properties

I am currently writing an application which should use a replica set of MongoDB. It is a Spring Boot based application and the following properties work perfectly fine to connect to one server: ...
incredibleholg's user avatar
26 votes
3 answers
21k views

Lombok - java.lang.StackOverflowError: null on toString method

I have two classes Product and Categorie. When I would like to modify the list of products in categorie with categoryRepository.save(c1) as shown in the code below, this error occurs: java.lang....
Gary's user avatar
  • 297
26 votes
4 answers
21k views

How to I get Spring-Data-MongoDB to validate my objects?

I have a very simple Spring Boot application that uses Spring-Data-Mongodb All I want to do is set a JSR-303 validation rule that says the object I'm saving must have a username. I read that JSR-303 ...
Zac Tolley's user avatar
  • 2,340
26 votes
2 answers
19k views

Spring Data MongoRepository save(T) not working... sometimes

So there's this little Angular + Java + Spring Boot + MongoDB app I'm working with. It's getting quite a lot of action (read: code modifications) lately, but the data access classes have gone largely ...
walen's user avatar
  • 7,184
24 votes
5 answers
16k views

Springboot With Mongodb Error while using find*() query

I am getting the following error: at com.aks.springStorage.SpringStorageApplication.main(SpringStorageApplication.java:22) [classes/:na] Caused by: org.springframework.data.mongodb....
Akhil Patro's user avatar
24 votes
4 answers
30k views

No bean named 'mongoTemplate' available. Spring Boot + MongoDB

I'm building a backend using Spring Boot and MongoDB, first I'm making the user repository, service, and controller, and getting this error: *************************** APPLICATION FAILED TO START ****...
Benjamín Paolo Díaz García's user avatar
24 votes
4 answers
22k views

How to cascade delete document in mongodb?

I have user and photo documents in Mongodb. Each photo belongs to user and a photo maybe shared among users. Lets say user1 has p1,p2,p3 photos and user2 has p3,p4,p5 photos. If I delete user1 (...
ace's user avatar
  • 11.8k
23 votes
14 answers
37k views

Why does my flapdoodle Embedded MongoDB test fail to run? (creating 'embeddedMongoServer' could not start process EOF)

I'm having trouble getting my brand new project to build. I used https://start.spring.io/ to generate a fresh new Spring 2.0 MongoDB Maven project, and I want to have an embedded MongoDB database for ...
SnoopDougg's user avatar
  • 1,577
21 votes
2 answers
67k views

How can we create Auto generated field for mongodb using spring boot

I write some code.I want to make questionId field in BaseQuestion Class as Autogenerated.Any solution for that? I am not using jpa jar.so i can't use @Generatedvalue annotation.So how we show here ...
Saakshi Aggarwal's user avatar
20 votes
4 answers
44k views

Log MongoDB queries with Spring Boot

Is it possible to log all MongoDB queries in my Spring Boot app? I tried this: logging.level.org.springframework.data.document.mongodb=INFO log4j.category.org.springframework.data.document.mongodb=...
Fabio Ebner's user avatar
  • 2,693
20 votes
5 answers
46k views

Authentication error when accessing mongodb through Spring Boot app

I have some trouble connecting to a remote mongodb from a java spring boot application. The MongoDB server has no firewall set up, and I can connect to mongo remotely from another machine. I have a ...
IndyStef's user avatar
  • 777
20 votes
1 answer
23k views

CodecConfigurationException when saving ZonedDateTime to MongoDB with Spring Boot >= 2.0.1.RELEASE

I was able to reproduce my problem with a minimal modification of the official Spring Boot guide for Accessing Data with MongoDB, see https://github.com/thokrae/spring-data-mongo-zoneddatetime. After ...
tdkBacke's user avatar
  • 595
20 votes
7 answers
20k views

Specify field is transient for MongoDB but not for RestController

I'm using spring-boot to provide a REST interface persisted with MongoDB. I'm using the 'standard' dependencies to power it, including spring-boot-starter-data-mongodb and spring-boot-starter-web. ...
Carlos Bribiescas's user avatar
19 votes
2 answers
34k views

AuthenticationFailed to mongoDB with Spring boot

I'm trying to create a server where my webpage / app can make calls, from now I'm starting with Login so, I've created the Server according my needs, the problem is on application.properties that I'm ...
StuartDTO's user avatar
  • 823
19 votes
2 answers
31k views

Storing java 8 LocalDate in mongo DB

Using Spring Boot 1.5.4.RELEASE and Mongo driver 3.4.2. I want to store LocalDate in mongo DB, but I am facing a weird problem: LocalDate startDate = LocalDate.now(); LocalDate endDate = LocalDate.of(...
Mehraj Malik's user avatar
  • 15.3k
19 votes
2 answers
3k views

Mongo driver with @Testcontainers, throws exceptions after tests run successfully

I'm setting up integration tests in a sample spring boot kotlin project, using testcontainers:mongodb. I've set up a MongoDBContaine, and everything works as expected - the app connects to the mongodb ...
eja's user avatar
  • 5,051
18 votes
7 answers
35k views

Spring Custom Query with pageable

I want to to implement pagination in spring application.I know using repository we can implement pagination but we can not write our own query for data retrieve there are limited methods in repository ...
Trivikrama's user avatar
18 votes
3 answers
15k views

How can you load initial data in MongoDB through Spring Boot?

Is it possible to load initial data in a MongoDB database using src/main/resources/data.sql or by any other file? I understand that data.sql is used for SQL DB's whereas MongoDB is a NOSQL DB. But ...
Nital's user avatar
  • 5,954
17 votes
3 answers
16k views

Using RepositoryRestResource annotation to change RESTful endpoint not working

I am new to Spring boot. I was trying to create RESTful web service which also plugs into MongoDB. Everything works fine as the guide explains except for this. package hello.requests; import java....
Codevalley's user avatar
  • 4,653
16 votes
7 answers
7k views

Spring Boot MongoDB Connectivity Issue

My Spring Boot application is trying to connect to MongoDB Database. The configuration is added on application.yml file. The application was working completely fine locally till yesterday. But when ...
ekansh's user avatar
  • 746
16 votes
5 answers
30k views

How can a store raw JSON in Mongo using Spring Boot

I'd like to take HTTP PUT request with JSON and store it unmodified in Mongo. How can I do this? The best I have is this: @RestController public class ConfigurationController { @Autowired ...
user2732949's user avatar
  • 1,203
16 votes
3 answers
27k views

Spring Boot connect Mysql and MongoDb

I have a problem with Spring Boot application. I want to connect a MongoDB database and a MySql database in my Spring boot application. I would to know if it is possible, in positive case How I can ...
andrea cenciarelli's user avatar
16 votes
6 answers
117k views

Consider defining a bean of type in your configuration

I am following this tutorial ( https://www.youtube.com/watch?v=Hu-cyytqfp8 ) and trying to connect to MongoDB on a remote server in Spring Boot. I get the following message when I run the application....
Chase's user avatar
  • 195
14 votes
6 answers
33k views

could not found bean for MongoRepository (Spring Boot)

I am using spring boot and MongoDB. Spring version : 4.3.9 Spring boot version : 1.5.4 I am creating a repository which implements MongoRepository interface, like below import org.springframework....
Mehraj Malik's user avatar
  • 15.3k
14 votes
2 answers
11k views

Why does subscribe work and block doesn't in Spring reactive Mongo?

I created a project fresh out of the Spring Initializr by choosing Kotlin, Gradle, M7 and Web-reactive. I made a small project: data class Person (val id: String) @Component class PersonHandler(val ...
Martin Drozdik's user avatar
14 votes
2 answers
3k views

Spring MongoDB query documents if days difference is x days

I have a collection that has two date fields and I am trying to query all records that have a difference of 15 days: { "_id" : "someid", "factoryNumber" : 123, "factoryName" : "some factory ...
jedgard's user avatar
  • 868
14 votes
1 answer
2k views

Creating a capped collection using Spring data MongoDB @Document

I am trying out reactive support in spring-data with MongoDB. I am using spring-boot 2.0.0. Generally I would write a domain object like this in my project: @Document public class PriceData { ......
pvpkiran's user avatar
  • 26.5k
13 votes
5 answers
17k views

Spring boot / mongo wont create index with the index annotation

I have the following: @Document(collection = "linkmetadata") public class LinkMetaData { @Indexed(unique = true) private String url; ... } But whenever it creates the collection it doesn't create ...
Jonas B's user avatar
  • 2,361
13 votes
8 answers
48k views

Set Mongo Timeout in Spring Boot

I am using spring boot web application which connects to mongo db which is working out of the box. I just use the following properties: spring.data.mongodb.host=myHost spring.data.mongodb.port=27017 ...
Noor Syed's user avatar
  • 630
13 votes
7 answers
25k views

How to configure a MongoDB cluster which supports sessions?

I want to explore the new transaction feature of MongoDB and use Spring Data MongoDB. However, I get the exception message "Sessions are not supported by the MongoDB cluster to which this client is ...
Juergen Zimmermann's user avatar
12 votes
2 answers
12k views

I can't exclude MongoAutoConfiguration in Springboot-Kotlin (MongoSocketOpenException)

I'm getting a MongoSocketOpenException when trying to exclude MongoAutoConfiguration. I'm trying to connect to a remote MongoDB. Is the @EnableAutoConfiguration syntax correct considering I'm working ...
Martin Erlic's user avatar
  • 5,637
12 votes
3 answers
15k views

Cannot create namespace in multi-document transaction(MongoDB 4.0, Spring Data 2.1.0, Spring Boot)

This question regarding to Spring boot, Mongo4.0, Spring-data application. I have upgraded from MongoDB 3.6.x to MongoDB 4.0 and Spring data 2.0.x to Spring-data 2.1.0 for transactional management ...
Srini's user avatar
  • 853
12 votes
4 answers
16k views

Please use 'MongoMappingContext#setAutoIndexCreation(boolean)' or override 'MongoConfigurationSupport#autoIndexCreation()' to be explicit

I went through https://docs.spring.io/spring-data/mongodb/docs/2.2.0.RC1/reference/html/#mapping-usage and other sources on the web, but the solution did not work for me. I am using Spring Boot 2.2.2....
Prateek's user avatar
  • 11.3k
12 votes
5 answers
36k views

Getting MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017

I want to establish a connection with my MongoDB database running in docker. Application seemingly starts without any problem but when I am trying to call any request like simple GET: localhost:8082/...
Martin's user avatar
  • 1,199
12 votes
4 answers
64k views

com.mongodb.MongoSocketOpenException: Exception opening socket(MongoDB, Docker)

I try to starting my application(Spring Boot + Spring Cloud + Eureka + MongoDB) with using docker image, but i can't get connection to MongoDB. Exception: exception "com.mongodb....
bsuart's user avatar
  • 361
12 votes
2 answers
28k views

How can I join two collections spring-data-mongdb as ManyToMany (RDBMS)

I have this sample example from https://github.com/szerhusenBC/jwt-spring-security-demo/ that I'm trying to use mongodb as my backend, but I'm getting error because of the code in JwtUserFactory.java ...
user525146's user avatar
  • 3,958
12 votes
3 answers
30k views

MockBean annotation in Spring Boot test causes NoUniqueBeanDefinitionException

I am having trouble using the @MockBean annotation. The docs say MockBean can replace a bean within the context, but I am getting a NoUniqueBeanDefinitionException within my unit test. I can't see how ...
JCN's user avatar
  • 509
12 votes
1 answer
8k views

Differences between com.mongodb.client.MongoClient and com.mongodb.MongoClient

I'm a bit new in MongoDB and I got confused with MongoClient classes as there are two in different packages (com.mongodb.client.MongoClient and com.mongodb.MongoClient). And what I have seen is that ...
PhoneixS's user avatar
  • 10.8k
12 votes
2 answers
872 views

Insert embeded document without reading whole document - spring, mongo

I have this factory collection : @Document(collection = "factory") public class Factory { Private List<Product> products; } which embeds the Product as products. When I have to ...
Nilanka Manoj's user avatar
11 votes
4 answers
16k views

How to use embedded MongoDB with SpringBoot v3.0.0?

I'm trying to connect embedded mongodb and test it with MongoDbSpringIntegrationTest. The problem is that the identical code works with spring boot in 2.7.7 but doesn't work with spring boot in 3.0.0. ...
Suori's user avatar
  • 111
11 votes
1 answer
14k views

How to upload and retrieve file in mongodb in spring boot application without using GridFSTemplate?

I want to upload files and retrieve them from mongodb in spring boot application. But I don't want to use GridFSTemplate because my file size will not be greater than 16 MB. I am not choosing ...
Sarvesh's user avatar
  • 581
11 votes
1 answer
21k views

MongoRepository findByThisAndThat custom @Query with multiple parameters

I am trying to run this query {campaignId: ObjectId('5a6b11e806f0252e1408e379'),'options.path': 'NT'} it works perfectly in Compass, but when I try to add in MongoRepository interface like below: @...
shabby's user avatar
  • 3,112
11 votes
2 answers
31k views

Spring Boot with MongoTemplate

I am new to Spring Boot and MongoDb. Trying some examples with Mongo Repositories and Spring Boot. But after going through some of the documents found that Mongo Template is will be a better option. ...
umesh's user avatar
  • 322
11 votes
3 answers
20k views

Spring boot 2.0.5.RELEASE and mongo 4.0 connection issues

I am following the Accessing Data with MongoDB tutorial on Spring web site I Installed Mongo DB server version 4 as a service Its authentication is working fine when I connect to it using a a client. ...
JavaSheriff's user avatar
  • 7,378

1
2 3 4 5
61