/** * Get the count of documents in collection. * * @return the number of documents in collection * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long getCount() { return getCount(new BasicDBObject(), new DBCollectionCountOptions()); }
/** * Same as {@link #getCount()} * * @return the number of documents in collection * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long count() { return getCount(new BasicDBObject(), new DBCollectionCountOptions()); }
/** * Get the count of documents in collection that would match a criteria. * * @param query specifies the selection criteria * @return the number of documents that matches selection criteria * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long getCount(@Nullable final DBObject query) { return getCount(query, new DBCollectionCountOptions()); }
/** * Same as {@link #getCount(DBObject)} * * @param query specifies the selection criteria * @return the number of documents that matches selection criteria * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long count(@Nullable final DBObject query) { return getCount(query, new DBCollectionCountOptions()); }
/** * Get the count of documents in collection that would match a criteria. * * @param query specifies the selection criteria * @param projection this is ignored * @param limit limit the count to this value * @param skip number of documents to skip * @param readPreference {@link ReadPreference} to be used for this operation * @return the number of documents that matches selection criteria * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count * @deprecated Prefer {@link #count(DBObject, DBCollectionCountOptions)} */ @Deprecated public long getCount(@Nullable final DBObject query, @Nullable final DBObject projection, final long limit, final long skip, final ReadPreference readPreference) { return getCount(query, new DBCollectionCountOptions().limit(limit).skip(skip).readPreference(readPreference)); }
private DBCollectionCountOptions getDbCollectionCountOptions() { DBCollectionCountOptions countOptions = new DBCollectionCountOptions() .readPreference(getReadPreferenceForCursor()) .readConcern(getReadConcern()) .collation(getCollation()) .maxTime(findOptions.getMaxTime(MILLISECONDS), MILLISECONDS); Object hint = findOptions.getHint() != null ? findOptions.getHint() : findOptions.getModifiers().get("$hint"); if (hint != null) { if (hint instanceof String) { countOptions.hintString((String) hint); } else { countOptions.hint((DBObject) hint); } } return countOptions; } }
/** * Same as {@link #getCount()} * * @return the number of documents in collection * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long count() { return getCount(new BasicDBObject(), new DBCollectionCountOptions()); }
/** * Get the count of documents in collection. * * @return the number of documents in collection * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long getCount() { return getCount(new BasicDBObject(), new DBCollectionCountOptions()); }
/** * Same as {@link #getCount(DBObject)} * * @param query specifies the selection criteria * @return the number of documents that matches selection criteria * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long count(@Nullable final DBObject query) { return getCount(query, new DBCollectionCountOptions()); }
/** * Get the count of documents in collection that would match a criteria. * * @param query specifies the selection criteria * @return the number of documents that matches selection criteria * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long getCount(@Nullable final DBObject query) { return getCount(query, new DBCollectionCountOptions()); }
/** * Get the count of documents in collection that would match a criteria. * * @param query specifies the selection criteria * @param projection this is ignored * @param limit limit the count to this value * @param skip number of documents to skip * @param readPreference {@link ReadPreference} to be used for this operation * @return the number of documents that matches selection criteria * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count * @deprecated Prefer {@link #count(DBObject, DBCollectionCountOptions)} */ @Deprecated public long getCount(@Nullable final DBObject query, @Nullable final DBObject projection, final long limit, final long skip, final ReadPreference readPreference) { return getCount(query, new DBCollectionCountOptions().limit(limit).skip(skip).readPreference(readPreference)); }
private DBCollectionCountOptions getDbCollectionCountOptions() { DBCollectionCountOptions countOptions = new DBCollectionCountOptions() .readPreference(getReadPreferenceForCursor()) .readConcern(getReadConcern()) .collation(getCollation()) .maxTime(findOptions.getMaxTime(MILLISECONDS), MILLISECONDS); Object hint = findOptions.getHint() != null ? findOptions.getHint() : findOptions.getModifiers().get("$hint"); if (hint != null) { if (hint instanceof String) { countOptions.hintString((String) hint); } else { countOptions.hint((DBObject) hint); } } return countOptions; } }