本文整理汇总了Java中com.mongodb.client.model.CountOptions类的典型用法代码示例。如果您正苦于以下问题:Java CountOptions类的具体用法?Java CountOptions怎么用?Java CountOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CountOptions类属于com.mongodb.client.model包,在下文中一共展示了CountOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateIfMatch
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
/**
* 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");
}
}
示例2: exists
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
@Override
public boolean exists(String id) {
Observable<Long> count =
getCollection().count(Filters.eq("id", id), new CountOptions().limit(1));
return count.toBlocking().single() > 0;
}
示例3: isValid
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
@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;
}
示例4: count
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
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");
}
}
示例5: testCount
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
@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()));
}
示例6: count
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
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);
}
});
}
示例7: count
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
public long count(final Bson filter, final CountOptions options) {
if (options == null) {
return coll.count(filter);
} else {
return coll.count(filter, options);
}
}
示例8: count
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
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);
}
});
}
示例9: count
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
@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);
}
示例10: count
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
@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);
}
}));
}
示例11: exists
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
@Override
public boolean exists(String userName) {
Observable<Long> count =
getCollection().count(Filters.eq("name", userName), new CountOptions().limit(1));
return count.toBlocking().single() > 0;
}
示例12: count
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
public long count(final String collectionName, final Bson filter, final CountOptions options) {
return collExecutor(collectionName).count(filter, options);
}
示例13: exists
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
public boolean exists(final Bson filter) {
return coll.count(filter, new CountOptions().limit(1)) > 0;
}
示例14: getSize
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
@Override
public long getSize(int max) {
CountOptions co = new CountOptions();
co.limit(max);
return table.getCollection().count(query.getQuery());
}
示例15: size
import com.mongodb.client.model.CountOptions; //导入依赖的package包/类
public long size(final long maxTime, final TimeUnit timeUnit) {
return collection().count(new BsonDocument(), new CountOptions().maxTime(maxTime, timeUnit));
}