@Signature public long count(BasicDBObject filter) { return getWrappedObject().count(filter); }
protected long doCount(String collectionName, Document filter, CountOptions options) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing count: {} in collection: {}", serializeToJsonSafely(filter), collectionName); } if (MongoDatabaseUtils.isTransactionActive(getMongoDbFactory())) { return execute(collectionName, collection -> collection.countDocuments(filter, options)); } return execute(collectionName, collection -> collection.count(filter, options)); }
@Signature public long count() { return getWrappedObject().count(); }
protected long doCount(String collectionName, Document filter, CountOptions options) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing count: {} in collection: {}", serializeToJsonSafely(filter), collectionName); } if (MongoDatabaseUtils.isTransactionActive(getMongoDbFactory())) { return execute(collectionName, collection -> collection.countDocuments(filter, options)); } return execute(collectionName, collection -> collection.count(filter, options)); }
@Signature public long count(BasicDBObject filter, CountOptions options) { return getWrappedObject().count(filter, options); }
@Test public void testInsert() { String name = "some_collection"; MongoCollection<Document> collection = getMongoClient().getDatabase(TEST_DB_NAME).getCollection(name); this.getAds().insert(name, new TestEntity()); Assert.assertEquals(1, collection.count()); this.getAds().insert(name, new TestEntity(), new InsertOptions() .writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(2, collection.count()); }
@Test public void testBulkInsertWithNullWC() { this.getAds().insert(asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions()); Assert.assertEquals(5, getDs().getCollection(TestEntity.class).count()); String name = "some_collection"; this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions()); Assert.assertEquals(5, getMongoClient().getDatabase(TEST_DB_NAME).getCollection(name).count()); }
@Test @SuppressWarnings("deprecation") public void testBulkInsertOld() { this.getAds().insert(asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, getDs().getCollection(TestEntity.class).count()); String name = "some_collection"; MongoCollection<Document> collection = getMongoClient().getDatabase(TEST_DB_NAME).getCollection(name); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, collection.count()); collection.drop(); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), WriteConcern.ACKNOWLEDGED); Assert.assertEquals(5, collection.count()); }
@Test public void testBulkInsert() { this.getAds().insert(asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, getDs().getCollection(TestEntity.class).count()); String name = "some_collection"; MongoCollection<Document> collection = getMongoClient().getDatabase(TEST_DB_NAME).getCollection(name); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, collection.count()); collection.drop(); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions() .writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, collection.count()); }
@Test public void withDate() { final Date date = new Date(); final ObjectId id = ObjectId.get(); final Jackson expected = ImmutableJackson.builder() .id(id) .prop1("prop1") .prop2("22") .date(new Date(date.getTime())) .build(); repository.insert(expected).getUnchecked(); check(collection.count()).is(1L); final Jackson actual = repository.findAll().fetchAll().getUnchecked().get(0); check(expected).is(actual); final BsonDocument doc = collection.find().first(); check(doc.keySet()).hasContentInAnyOrder("_id", "prop1", "prop2", "date", "uuid"); check(doc.get("date").asDateTime().getValue()).is(date.getTime()); check(doc.get("_id").asObjectId().getValue()).is(id); }
/** * Gets a count of documents which match the query * * @param query * query to match * @return The count * @throws MongoException * If an error occurred */ public long getCount(Document query) throws MongoException { return mongoCollection.count(query); }
/** * Check if the lock is held. Could be used by external process for example. * * @param db MongoDatabase object * @return true if the lock is currently held */ public boolean isLockHeld(MongoDatabase db) { return db.getCollection(lockCollectionName).count() == 1; }
/** {@inheritDoc} */ @Override public boolean existGroup(String groupName) { if (groupName == null || groupName.isEmpty()) { throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY); } return getFeaturesCollection().count(BUILDER.getGroupName(groupName)) > 0; }
@Override @Deprecated public long count(@NotNull ClientSession clientSession) { return collection.count(clientSession); }
@Override @Deprecated public long count(@NotNull Bson filter) { return collection.count(filter); }
@Override @Deprecated public long count(@NotNull ClientSession clientSession, @NotNull Bson filter, @NotNull CountOptions options) { return collection.count(clientSession, filter, options); }
/** {@inheritDoc} */ @Override public boolean exist(String featId) { Util.assertHasLength(featId); return 1 == getFeaturesCollection().count(BUILDER.getFeatUid(featId)); }
/** {@inheritDoc} */ public boolean existProperty(String name) { Util.assertHasLength(name); return 1 == getPropertiesCollection().count(BUILDER.getName(name)); }
@Override public boolean isQueueEmpty() { return (int) collRefs.count(eq(IMongoSerializer.FIELD_STAGE, Stage.QUEUED.name()), new CountOptions().limit(1)) == 0; }