All other methods in the DatabaseHanlder.java file return a list of documents (i.e., repos) that will be later used by the printRepositories(List<Document>) function to be printed elegantly. However, this is not the case with getRandomRepositories(int num).
Fix
To make the code more robust and functional, modify this function to return a list of repositories like other functions so that its content would be neatly printed like the rest (currently, even the _id is being printed).
public List<Document> getRandomRepositories(int num) {
// Aggregation pipeline for randomly selecting `num` number of documents
List<Document> randomEntries = reposCollection.aggregate(
Arrays.asList(
Aggregates.sample(num)
)
).into(new java.util.ArrayList<>());
// Return the retrieved documents
return randomEntries;
}
Issue
All other methods in the
DatabaseHanlder.java
file return a list of documents (i.e., repos) that will be later used by theprintRepositories(List<Document>)
function to be printed elegantly. However, this is not the case withgetRandomRepositories(int num)
.Fix
To make the code more robust and functional, modify this function to return a list of repositories like other functions so that its content would be neatly printed like the rest (currently, even the
_id
is being printed).