I have been searching through the world wide web for hours and I can't find a viable solution to my problem:
It is simple: I want to search through a collection of items from my MongoDB and return all the documents.
From a RESTFul API perspective : GET /items - Returns all items in the collection. Not sorted
// NOT WORKING - STILL TRYING
public static String getItems() {
StringBuilder items = new StringBuilder();
MongoCursor<Document> cursor = itemCollection.find().iterator();
try {
while (cursor.hasNext()) {
items.append(cursor.next().toJson());
}
} finally {
cursor.close();
}
return items.toString();
}
As you can see I return a StringBuilder, since I want to concatenate every document into one big bulk. But this returns as TEXT and not JSON. See below:
This is when the read type is set as JSON

The below is when the read type is set to TEXT, which creates the output I need, but it is not the correct format.
I can't return it as a Document and then use the method: toJson(), since it will only return the last entry. I've tried with Lists, but it can't be converted into JSON documents. The above is the closest I get to what I need.
I hope someone in here has been through the same issue as me and can give a quick tip to solve the issue I'm having :-).
