Relative Content

Tag Archive for javamongodbspring-boot

Unable to authenticate request to mongodb from springboot application

I have a problem with a request from my springboot application on mongo (docker), while trying to establish authentication on mongoDB (as soon as I turn it off, the application runs correctly).
Docker mongoDb setting :
mongodb-master:
image: mongo:6.0.3
ports:
– “27017:27017”
environment:
MONGO_INITDB_ROOT_USERNAME: USERNAME
MONGO_INITDB_ROOT_PASSWORD: PASS
hostname: mongodb-master

MongoDB rest api with spring boot, findById() Type question

im learning how to make a rest api with java Spring and combining it with mongoDB. Im trying to make a simple CRUD with a customer object. For now it is working great, but im having issues with the findById() Method. Since mongoDB creates an _id for me which is a String, how do i use the built in method findById() since it is requiring a long as a parameter. Here is my code for my method.

JSON reader was expecting a value but found ‘Document

I am trying to build the aggregate pipeline and somewhere it is causing an issue. To debug the issue, I’m trying to print the MongoDB query in JSON. Below is the syntax of code and it is causing an issue JSON reader was expecting a value but found ‘Document

Spring Boot MongoDB generic Pagination

I am following this tutorial Spring Boot MongoDB Pagination example with Spring Data
And I am wondering if there is a way to make the java code generic
So I can use this code for all my collections without the need to create the POJOs’
for example
in the code he is building the Tutorial Pojo: