Search in sources :

Example 16 with CountOptions

use of com.mongodb.client.model.CountOptions in project core-ng-project by neowu.

the class MongoCollectionImpl method count.

@Override
public long count(Count count) {
    StopWatch watch = new StopWatch();
    Bson filter = count.filter == null ? new BsonDocument() : count.filter;
    try {
        return collection(count.readPreference).count(filter, new CountOptions().maxTime(mongo.timeoutInMs, TimeUnit.MILLISECONDS));
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("mongoDB", elapsedTime, 1, 0);
        logger.debug("count, collection={}, filter={}, readPref={}, elapsedTime={}", collectionName, new BsonParam(filter, mongo.registry), count.readPreference == null ? null : count.readPreference.getName(), elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : BsonDocument(org.bson.BsonDocument) CountOptions(com.mongodb.client.model.CountOptions) StopWatch(core.framework.util.StopWatch) Bson(org.bson.conversions.Bson)

Example 17 with CountOptions

use of com.mongodb.client.model.CountOptions in project jphp by jphp-compiler.

the class CountOptionsMemoryOperation method convert.

@Override
public CountOptions convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
    if (arg.isNull())
        return null;
    ArrayMemory arr = arg.toValue(ArrayMemory.class);
    CountOptions options = new CountOptions();
    if (arr.containsKey("skip"))
        options.skip(arg.valueOfIndex("skip").toInteger());
    if (arr.containsKey("limit"))
        options.limit(arg.valueOfIndex("limit").toInteger());
    if (arr.containsKey("maxTime")) {
        options.maxTime(WrapTimer.parsePeriod(arg.valueOfIndex("maxTime").toString()), TimeUnit.MILLISECONDS);
    }
    return options;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) CountOptions(com.mongodb.client.model.CountOptions)

Aggregations

CountOptions (com.mongodb.client.model.CountOptions)17 Document (org.bson.Document)8 Test (org.junit.jupiter.api.Test)7 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)6 Test (org.junit.Test)5 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)4 Query (org.springframework.data.mongodb.core.query.Query)4 BsonDocument (org.bson.BsonDocument)3 Bson (org.bson.conversions.Bson)3 UpdateOptions (com.mongodb.client.model.UpdateOptions)2 EstimatedDocumentCountOptions (com.mongodb.client.model.EstimatedDocumentCountOptions)1 ClientSession (com.mongodb.reactivestreams.client.ClientSession)1 StopWatch (core.framework.util.StopWatch)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 MongoDBResult (org.apache.gora.mongodb.query.MongoDBResult)1 GoraException (org.apache.gora.util.GoraException)1 ArrayMemory (php.runtime.memory.ArrayMemory)1