/** * Get the count of documents in collection. * * @param readPreference {@link ReadPreference} to be used for this operation * @return the number of documents in collection * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count */ public long getCount(final ReadPreference readPreference) { return getCount(new BasicDBObject(), null, readPreference); }
@Override public long count() { return dbColl.getCount(getQueryObject()); }
/** * 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 * @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 */ public long count(@Nullable final DBObject query, final ReadPreference readPreference) { return getCount(query, null, readPreference); }
/** * 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()); }
/** * Get the count of documents in collection that would match a criteria. * * @param query specifies the selection criteria * @param options the options for the count operation. * @return the number of documents that matches selection criteria * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/count/ Count * @since 3.4 */ public long count(@Nullable final DBObject query, final DBCollectionCountOptions options) { return getCount(query, options); }
/** * Get the count of documents in collection that would match a criteria. * * @param query specifies the selection criteria * @param projection this is ignored * @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, final DBObject projection) { return getCount(query, projection, 0, 0); }
@Override @Deprecated public long countAll() { final DBObject query = getQueryObject(); if (LOG.isTraceEnabled()) { LOG.trace("Executing count(" + dbColl.getName() + ") for query: " + query); } return dbColl.getCount(query); }
/** * Get the count of documents in collection that would match a criteria. * * @param query specifies the selection criteria * @param projection this is ignored * @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 ReadPreference readPreference) { return getCount(query, projection, 0, 0, readPreference); }
/** * Counts the number of objects matching the query. This does not take limit/skip into consideration, and does initiate a call to the * server. * * @return the number of objects * @throws MongoException if the operation failed * @see DBCursor#size */ public int count() { DBCollectionCountOptions countOptions = getDbCollectionCountOptions(); return (int) collection.getCount(getQuery(), countOptions); }
/** * 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()); }
@Override public long count(final CountOptions options) { return dbColl.getCount(getQueryObject(), options.getOptions()); }
/** * 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 * @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) { return getCount(query, projection, limit, skip, getReadPreference()); }
assertThat(col.getCount(), Matchers.is(1L));
/** * 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)); }
/** * Counts the number of objects matching the query this does take limit/skip into consideration * * @return the number of objects * @throws MongoException if the operation failed * @see #count() */ public int size() { DBCollectionCountOptions countOptions = getDbCollectionCountOptions().skip(findOptions.getSkip()).limit(findOptions.getLimit()); return (int) collection.getCount(getQuery(), countOptions); }
/** * Test method for * {@link com.impetus.client.mongodb.schemamanager.MongoDBSchemaManager#dropSchema()} * . */ @Test public void testDropSchema() { emf = Persistence.createEntityManagerFactory(persistenceUnit); em = emf.createEntityManager(); getDB(); MongoDBClientFactory clientFactory = (MongoDBClientFactory) ClientResolver.getClientFactory(persistenceUnit); clientFactory.getSchemaManager(null).dropSchema(); DBCollection collection = db.getCollection("MongoDBEntitySimple"); Assert.assertTrue(collection.getIndexInfo().isEmpty()); Assert.assertEquals(0, collection.getCount()); collection = db.getCollection("GFS_BOOK.files"); Assert.assertTrue(collection.getIndexInfo().isEmpty()); Assert.assertEquals(0, collection.getCount()); collection = db.getCollection("GFS_BOOK.chunks"); Assert.assertTrue(collection.getIndexInfo().isEmpty()); Assert.assertEquals(0, collection.getCount()); }
/** * 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()); }