0)..." />

Increment field through java for Mongo

Currently there is a document for each question and I am trying to increment the "view" field. There is a DAO file and a Rest Service file. I'm struggling with returning the string after it has been changed. I think the source of the issue is mongo not liking the way it is converted to Json but I'm not entirely sure.

@GET

@Path("/{id}/views")

public String incrementViews( @PathParam("id")String questionId)

dao.incrementViews(questionId);

return dao.incrementViews(questionId);

}

Service Method

public String incrementViews(String questionId) {

ObjectId id;

id = new ObjectId(questionId);

Bson conditions = eq("_id", id);

Bson updates;

updates = Updates.inc(questionId, 1);

long count = questions.updateOne(conditions, updates).getModifiedCount();

if (count > 0)...

Read More »

By: StackOverFlow - Tuesday, 13 March

Related Posts