Example usage for com.mongodb.client MongoCursor close

List of usage examples for com.mongodb.client MongoCursor close

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor close.

Prototype

@Override
    void close();

Source Link

Usage

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereHugeIn() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(
                    Document.parse("{$match: {\"bsid\": {$in: [" + DemoData.joinByComma(DemoUtils.getBsIds())
                            + "]}}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();/*from   w  ww. j  a v a  2  s .c o  m*/

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereManyIn() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(
                    Document.parse("{$match: {\"prg\": {$in: [" + DemoData.SCALAR_IN_1_AS_STRING
                            + "]}, \"prr\": {$in: [" + DemoData.SCALAR_IN_2_AS_STRING + "]}}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();//from   w  w w  .  j  a v a2s.c  o m

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereManyHugeIn() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(
                    Document.parse("{$match: {\"prr\": {$in: [" + DemoData.SCALAR_IN_1_AS_STRING
                            + "]}, \"bsid\": {$in: [" + DemoData.joinByComma(DemoUtils.getBsIds()) + "]}}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();//from   w  w w  . j  av  a2s .  c  o  m

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereRange() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(
                    Document.parse("{$match: {\"vlc\": {$gt: " + DemoData.RANGE_LEFT + ", $lt: "
                            + DemoData.RANGE_RIGHT + "}}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();/*w w w  .  jav  a 2  s. co  m*/

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereManyRange() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(
                    Document.parse("{$match: {" + "$and: [" + "{\"vlc\": {$gt: " + DemoData.RANGE_LEFT
                            + ", $lt: " + DemoData.RANGE_RIGHT + "}}, {\"vch\": {$gt: " + DemoData.RANGE_LEFT
                            + ", $lt: " + DemoData.RANGE_RIGHT + "}}" + "]}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();//from w w  w.  j a  va2s .  c o m

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereStringLike() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(Document.parse("{$match: {tr: /" + DemoData.STRING_LIKE + "/}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();//from ww  w .  j  a v a 2s.  c o  m

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereString() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(Document.parse("{$match: {tr: \"" + DemoData.STRING_LIKE + "\"}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();/*from  w w  w . j a  v  a  2 s. co m*/

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object groupByWhereSimpleRangeInStringLike() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .aggregate(Arrays.asList(
                    Document.parse("{$match: {$and: [{prr: 1}, {prg: {$in: [" + DemoData.SCALAR_IN_1_AS_STRING
                            + "]}}, {vlc: {$gt: " + DemoData.RANGE_LEFT + ", $lt: " + DemoData.RANGE_RIGHT
                            + "}}, {tr: /" + DemoData.STRING_LIKE + "/}]}}"),
                    Document.parse("{$group: {_id: {prg: \"$prg\", prr: \"$prr\"}, count: {$sum: 1}}}")))
            .iterator();//from  w ww.ja va  2  s  . co  m

    Map<Integer, Map<Integer, Integer>> g = new HashMap<>();
    groupBy(g, cursor);
    cursor.close();
    return g;
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object selectLimit() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection.find(Document.parse("{\"prg\": {$in: ["
            + DemoData.SCALAR_IN_1_AS_STRING + "]}, \"prr\": {$in: [" + DemoData.SCALAR_IN_2_AS_STRING + "]}}"))
            .limit(25).iterator();//from w w w  .  ja v a2  s.  c  o m

    List<Object> r = new ArrayList<>();
    while (cursor.hasNext()) {
        r.add(cursor.next());
    }

    cursor.close();
    return r.size();
}

From source file:com.github.terma.fastselect.benchmark.PlayerMongoDb.java

License:Apache License

@Override
public Object selectOrderByLimit() throws Exception {
    MongoCollection collection = database.getCollection("myCollection");
    MongoCursor<Document> cursor = collection
            .find(Document.parse("{\"prg\": {$in: [" + DemoData.SCALAR_IN_1_AS_STRING + "]}, \"prr\": {$in: ["
                    + DemoData.SCALAR_IN_2_AS_STRING + "]}}"))
            .sort(Document.parse("{prr: 1}")).limit(25).iterator();

    List<Object> r = new ArrayList<>();
    while (cursor.hasNext()) {
        r.add(cursor.next());/*from   w  w w .  j av  a2  s.c o m*/
    }

    cursor.close();
    return r.size();
}