List of usage examples for com.mongodb DBCursor toArray
public List<DBObject> toArray(final int max)
From source file:mongodb.findDocument.java
public static void getManyToArray(DBCollection collection) { System.out.println("\nConverted to array iteration: "); DBCursor cursor = collection.find(); List<DBObject> docs = cursor.toArray(5); for (final DBObject doc : docs) { System.out.println(doc.get("word")); }/*w w w. ja v a 2s.co m*/ }
From source file:org.mongodb.workshop.api.ComicsService.java
License:Apache License
@GET @Path("/") @ApiOperation(value = "Return Comics using pagination") public DBObject all(@DefaultValue("1") @QueryParam("page") int page) { long count = comicsCollection.count(); int skip = ITEMS_PER_PAGE * (page - 1); DBCursor cursor = comicsCollection.find().skip(skip).limit(ITEMS_PER_PAGE); List<DBObject> items = cursor.toArray(cursor.size()); ResultDBObject result = new ResultDBObject(count, ITEMS_PER_PAGE, page, items); return result; }
From source file:org.mongodb.workshop.api.ComicsService.java
License:Apache License
@GET @Path("/search") @ApiOperation(value = "Full text search on comics") public DBObject search(@DefaultValue("1") @QueryParam("page") int page, @QueryParam("keyword") String keyword) { DBObject query = QueryBuilder.start().text(keyword).get(); DBObject proj = BasicDBObjectBuilder.start().append("title", 1).append("description", 1).push("score") .append("$meta", "textScore").get(); DBObject sort = BasicDBObjectBuilder.start().push("score").append("$meta", "textScore").get(); long count = comicsCollection.count(query); int skip = ITEMS_PER_PAGE * (page - 1); DBCursor cursor = comicsCollection.find(query, proj).sort(sort).skip(skip).limit(ITEMS_PER_PAGE); List<DBObject> items = cursor.toArray(cursor.size()); ResultDBObject result = new ResultDBObject(count, ITEMS_PER_PAGE, page, items); return result; }
From source file:org.mongodb.workshop.api.CreatorsService.java
License:Apache License
@GET @Path("/") @ApiOperation(value = "Return Creators using pagination") public DBObject all(@DefaultValue("1") @QueryParam("page") int page) { long count = creatorsCollection.count(); int skip = ITEMS_PER_PAGE * (page - 1); DBCursor cursor = creatorsCollection.find().skip(skip).limit(ITEMS_PER_PAGE); List<DBObject> items = cursor.toArray(cursor.size()); ResultDBObject result = new ResultDBObject(count, ITEMS_PER_PAGE, page, items); return result; }
From source file:org.mongodb.workshop.api.CreatorsService.java
License:Apache License
@GET @Path("/search") @ApiOperation(value = "Full text search on Creators") public DBObject search(@DefaultValue("1") @QueryParam("page") int page, @QueryParam("comicsName") String comicsName) { DBObject query = QueryBuilder.start().put("comics.items.name") .regex(java.util.regex.Pattern.compile(comicsName, Pattern.CASE_INSENSITIVE)).get(); long count = creatorsCollection.count(query); int skip = ITEMS_PER_PAGE * (page - 1); DBCursor cursor = creatorsCollection.find(query).skip(skip).limit(ITEMS_PER_PAGE); List<DBObject> items = cursor.toArray(cursor.size()); ResultDBObject result = new ResultDBObject(count, ITEMS_PER_PAGE, page, items); return result; }