/** * Updates the document if the document's ETAG is matching the given etag (conditional put). * <p> * Using this method requires that the document contains an "etag" field that is updated if * the document is changed. * </p> * * @param value the new value * @param eTag the etag used for conditional update * @param maxTime max time for the update * @param timeUnit the time unit for the maxTime value * @return {@link UpdateIfMatchResult} */ public UpdateIfMatchResult updateIfMatch(final V value, final String eTag, final long maxTime, final TimeUnit timeUnit) { final K key = keyOf(value); if (key != null) { final Bson query = and(eq(AbstractMongoRepository.ID, key), eq(ETAG, eTag)); final Document updatedETaggable = collectionWithWriteTimeout(maxTime, timeUnit).findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER)); if (isNull(updatedETaggable)) { final boolean documentExists = collection() .count(eq(AbstractMongoRepository.ID, key), new CountOptions().maxTime(maxTime, timeUnit)) != 0; if (documentExists) { return CONCURRENTLY_MODIFIED; } return NOT_FOUND; } return OK; } else { throw new IllegalArgumentException("Key must not be null"); } }
@Override public boolean exists(String id) { Observable<Long> count = getCollection().count(Filters.eq("id", id), new CountOptions().limit(1)); return count.toBlocking().single() > 0; }
@Override public boolean isValid(String userName, String password) { Observable<Long> count = getCollection() .count(filter(userName, passwordUtil.toHash(password)), new CountOptions().limit(1)); return count.toBlocking().single() > 0; }
public long count(Bson mongoQuery, Date from, Date to, long timeout, TimeUnit timeUnit) throws TimeoutException { mongoQuery = buildQuery(mongoQuery, from, to); CountOptions options = new CountOptions(); options.maxTime(timeout, timeUnit); try { return threadInfoCollection.count(mongoQuery, options); } catch(MongoExecutionTimeoutException e) { throw new TimeoutException("Count exceeded time limit"); } }
@Test public void testCount() { assertEquals(8, coll.count()); assertEquals(4, coll.count(Filters.eq("name", "Alto"))); assertEquals(4, coll.count(Filters.eq("name", "Alto"), new CountOptions())); }
public CompletableFuture<Long> count(final String collectionName, final Bson filter, final CountOptions options) { return asyncExecutor.execute(new Callable<Long>() { @Override public Long call() throws Exception { return dbExecutor.count(collectionName, filter, options); } }); }
public long count(final Bson filter, final CountOptions options) { if (options == null) { return coll.count(filter); } else { return coll.count(filter, options); } }
public CompletableFuture<Long> count(final Bson filter, final CountOptions options) { return asyncExecutor.execute(new Callable<Long>() { @Override public Long call() throws Exception { return collExecutor.count(filter, options); } }); }
@Override public Observable<Long> count(final Bson filter, final CountOptions options) { return RxObservables.create(Observables.observe(new Block<SingleResultCallback<Long>>() { @Override public void apply(final SingleResultCallback<Long> callback) { wrapped.count(filter, options, callback); } }), observableAdapter); }
@Override public Publisher<Long> count(final Bson filter, final CountOptions options) { return new ObservableToPublisher<Long>(observe(new Block<SingleResultCallback<Long>>() { @Override public void apply(final SingleResultCallback<Long> callback) { wrapped.count(filter, options, callback); } })); }
@Override public Publisher<Long> count(final ClientSession clientSession, final Bson filter, final CountOptions options) { return new ObservableToPublisher<Long>(observe(new Block<SingleResultCallback<Long>>() { @Override public void apply(final SingleResultCallback<Long> callback) { wrapped.count(clientSession, filter, options, callback); } })); }
@Override public boolean exists(String userName) { Observable<Long> count = getCollection().count(Filters.eq("name", userName), new CountOptions().limit(1)); return count.toBlocking().single() > 0; }
public long count(final String collectionName, final Bson filter, final CountOptions options) { return collExecutor(collectionName).count(filter, options); }
public boolean exists(final Bson filter) { return coll.count(filter, new CountOptions().limit(1)) > 0; }
@Override public long getSize(int max) { CountOptions co = new CountOptions(); co.limit(max); return table.getCollection().count(query.getQuery()); }
@Override public Observable<Long> count() { return count(new BsonDocument(), new CountOptions()); }
@Override public Observable<Long> count(final Bson filter) { return count(filter, new CountOptions()); }
public long size(final long maxTime, final TimeUnit timeUnit) { return collection().count(new BsonDocument(), new CountOptions().maxTime(maxTime, timeUnit)); }
@Override public Publisher<Long> count() { return count(new BsonDocument(), new CountOptions()); }
@Override public Publisher<Long> count(final Bson filter) { return count(filter, new CountOptions()); }
@Override public Publisher<Long> count(final ClientSession clientSession) { return count(clientSession, new BsonDocument(), new CountOptions()); }
@Override public Publisher<Long> count(final ClientSession clientSession, final Bson filter) { return count(clientSession, filter, new CountOptions()); }
/** * Counts the number of documents in the collection according to the given options. * * @param filter the query filter * @param options the options describing the count * @return an Observable with a single element indicating the number of documents */ Observable<Long> count(Bson filter, CountOptions options);
/** * Counts the number of documents in the collection according to the given options. * * @param filter the query filter * @param options the options describing the count * @return a publisher with a single element indicating the number of documents */ Publisher<Long> count(Bson filter, CountOptions options);
/** * Counts the number of documents in the collection according to the given options. * * @param clientSession the client session with which to associate this operation * @param filter the query filter * @param options the options describing the count * @return a publisher with a single element indicating the number of documents * @mongodb.server.release 3.6 * @since 1.7 */ Publisher<Long> count(ClientSession clientSession, Bson filter, CountOptions options);