Package com.mongodb

Examples of com.mongodb.DBCursor.toArray()


    BasicDBObject condition = new BasicDBObject();
    condition.put(OWNER_ID, ownerId);
    BasicDBObject orderBy = new BasicDBObject();
    orderBy.put(TIME, -1);
    DBCursor cursor = collections.get(level).find(condition).skip(start).limit(end - start).sort(orderBy);
    return cursor.toArray();
  }

}
View Full Code Here


      DBCursor cursor = personalFeedDao.queryFeeds(ownerId, current, level);

      // while(cursor.hasNext()){
      // resultData.add(cursor.next());
      // }
      List<DBObject> feeds = cursor.toArray();
      resultData.addAll(feeds);

      // 当返回推信数目小于MIN_PAGE_SIZE,则将currentPage置为0,并会自动也去找下一级的personalFeed
      if (resultData.size() < MIN_PAGE_SIZE) {
        current = 0;
View Full Code Here

     
      //查询没有被订阅的记录
      //Tested
      DBCursor cursor = personalFeedDao.queryFeeds(idolIds, level, lastQueryTime);
      //Tested
      List<DBObject> newFeeds = cursor.toArray();
      //System.out.println(newFeeds.size());
      if ((newFeeds != null && newFeeds.size() > 0)) {
        //当查询到没有被订阅的记录时,就将其插入到订阅库中去
        //Tested
        subscribedFeedDao.insertFeeds(newFeeds, ownerId);
View Full Code Here

  @Override
  public List<DBObject> getNewFeeds(List<Long> idolIds, Long ownerId, Long lastQueryTime) {
    List<Long> idolIdsAction=idolIds;
    idolIdsAction.add(ownerId);
    DBCursor cursor = personalFeedDao.queryFeeds(idolIdsAction, 0, lastQueryTime);
    List<DBObject> newFeeds = cursor.toArray();
    subscribedFeedDao.insertFeeds(newFeeds, ownerId);
    return newFeeds;
  }
}
View Full Code Here

            if (limit != null) {
                ret.limit(limit.intValue());
            }
           
            Message out = exchange.getOut();
            out.setBody(ret.toArray());
            out.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret.count());
            out.setHeader(MongoDbConstants.RESULT_PAGE_SIZE, ret.size());
           
        } catch (Exception e) {
            // rethrow the exception
View Full Code Here

            if (limit != null) {
                ret.limit(limit.intValue());
            }

            Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.findAll);
            resultMessage.setBody(ret.toArray());
            resultMessage.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret.count());
            resultMessage.setHeader(MongoDbConstants.RESULT_PAGE_SIZE, ret.size());

        } catch (Exception e) {
            // rethrow the exception
View Full Code Here

            if (limit != null) {
                ret.limit(limit.intValue());
            }

            Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.findAll);
            resultMessage.setBody(ret.toArray());
            resultMessage.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret.count());
            resultMessage.setHeader(MongoDbConstants.RESULT_PAGE_SIZE, ret.size());
        } finally {
            // make sure the cursor is closed
            if (ret != null) {
View Full Code Here

        collection.insert(json("a:2, _id:4"));
        collection.insert(json("a:1, _id:3"));

        @SuppressWarnings("resource")
        DBCursor cursor = collection.find().sort(json("a:1, _id:-1"));
        assertThat(cursor.toArray()).containsExactly(json("a:1, _id:3"), json("a:1, _id:2"), json("a:1, _id:1"),
                json("a:2, _id:5"), json("a:2, _id:4"));
    }

    @Test
    public void testCountCommand() {
View Full Code Here

        collection.insert(json("_id: 4, counts:{done:1}"));
        collection.insert(json("_id: 5, counts:{done:2}"));

        @SuppressWarnings("resource")
        DBCursor cursor = collection.find(json("c: {$ne:true}")).sort(json("counts.done: -1"));
        assertThat(cursor.toArray()).containsExactly(json("_id: 5, counts:{done:2}"), json("_id: 4, counts:{done:1}"),
                json("_id: 1"), json("_id: 2"), json("_id: 3"));
    }

    @Test
    public void testFindAndModifyCommandEmpty() throws Exception {
View Full Code Here

        collection.insert(json("name: 'neil'"));
        collection.insert(json("name: 'neil'"));

        @SuppressWarnings("resource")
        DBCursor cursor = collection.find(json("name: 'neil'"));
        assertThat(cursor.toArray()).hasSize(2);
    }

    @Test
    public void testFindWithSkipLimit() {
        collection.insert(json("_id: 1"));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.