List of usage examples for com.mongodb.client MongoCollection count
@Deprecated
long count(ClientSession clientSession, Bson filter);
From source file:net.netzgut.integral.mongo.internal.services.MongoODMImplementation.java
License:Apache License
@Override public <T extends Serializable> long count(Bson filter, Class<T> entityClass, CountOptions options) { MongoCollection<Document> collection = this.mongo.getCollection(entityClass); return collection.count(filter, options); }
From source file:org.radarcns.mongo.util.MongoHelper.java
License:Apache License
/** * Finds whether document is available for given query parameters. * https://stackoverflow.com/a/8390458/822964 suggests find().limit(1).count(true) is the * optimal way to do it. In the Java driver, this is achieved by setting the count options. * * @param collection is the MongoDB that will be queried * @param projectName of the project//from w w w. j a va2s. co m * @param subjectId is the subjectID * @param sourceId is the sourceID * @param timeFrame is the time frame of the queried timewindow * @return a MongoDB cursor containing all documents from the query. */ public static boolean hasDataForSource(MongoCollection<Document> collection, String projectName, String subjectId, String sourceId, TimeFrame timeFrame) { createIndexIfNotAvailable(collection, indexProjectSubjectSourceTimestart); return collection.count(filterSource(projectName, subjectId, sourceId, timeFrame), new CountOptions().limit(1)) > 0; }