Glasnhost
Glasnhost

Reputation: 1135

spring-boot MongoDB find all return empty, how to troubleshoot it?

I have a simple spring-boot project for accessing items in a MongoDB:

@Autowired
private ItemRepository itemRepositoryDAO;
 ...
itemRepositoryDAO.findAll();

and in ItemRepository.java:

 .... 
 @Repository
 public interface ItemRepository extends MongoRepository<Item, String> {

 }

However findAll return always empty. If I connect to MongoDB from the shell, I can verify I have items. How can I troubleshoot this? MongoDB and spring are running inside docker.

Not much helpful logging.

What can I do?

Upvotes: 0

Views: 1984

Answers (1)

Arghya Sadhu
Arghya Sadhu

Reputation: 44559

Add below properties in application.properties

spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.type=trace

This should give more details about what SQL query is being executed against the DB.

Edit:

Turns out that a wrong collection name was being used in query.

Upvotes: 1

Related Questions