Skip to content

Tag: mongodb

Spring Boot + MongoDB Id query

I have a Spring Boot application combined with MongoDB as the persistance layer. I have the following structure: I also have a ResourceRepository: I found online that a way to have the id property returned in the JSON when you perform a GET request like http://localhost:8080/resources/ is to change the id pro…

MongoDB trying to connect to localhost, Why?

I am currently developing a Java application connected to a remote MongoDB databse. I have implemented the authentication methods fallowing the mongo guides: The app connect properly to the database but there is a thing i can’t understand.It connects well to the remote server,but I don’t know why …

Resolve DBRef into Json

I’m getting the following error in a Normalized Data Model structure in MongoDB: It’s caused by this line: Specifically the toJson() part. I have a DBRef Object in my Document, so I can reference a Document from another Collection. An Embedded Document Structure is not option. So how can I fix thi…

find in MongoCollection

I have a MongoCollection<Document> in which I assign a collection. I’m trying to find a user by his id. with that I’m getting an error java.lang.ClassCastException: com.mongodb.FindIterableImpl cannot be cast to org.bson.Document When I try I’m getting an error The method find(Bson, Cl…

Find all objects in collection Java Mongodb

Below code finds the first document in a collection : There does not appear to be a findAll method. How to find all the documents in the collection testCollection ? Answer You have to use the DBCollection.find() method, which Select all documents in collection and get a cursor to the selected documents. So, w…

Encrypt password fields in mongodb

I have following code, it insert the userName and password into database but the password is stored in plain text format. I mean when I’ll look into the db I can see the inserted password. I want to store password in encrypted format How can I achieve this? Answer According to the conversation in the co…