/*
 * Copyright 2008-present MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mongodb.client.model;

import com.mongodb.lang.Nullable;
import org.bson.conversions.Bson;

import java.util.concurrent.TimeUnit;

import static com.mongodb.assertions.Assertions.notNull;

The options for a count operation.
Since:3.0
@mongodb.driver.manualreference/command/count/ Count
/** * The options for a count operation. * * @since 3.0 * @mongodb.driver.manual reference/command/count/ Count */
public class CountOptions { private Bson hint; private String hintString; private int limit; private int skip; private long maxTimeMS; private Collation collation;
Gets the hint to apply.
Returns:the hint, which should describe an existing
/** * Gets the hint to apply. * * @return the hint, which should describe an existing */
@Nullable public Bson getHint() { return hint; }
Gets the hint string to apply.
Returns:the hint string, which should be the name of an existing index
Deprecated:Prefer getHint()
/** * Gets the hint string to apply. * * @return the hint string, which should be the name of an existing index * @deprecated Prefer {@link #getHint()} */
@Deprecated @Nullable public String getHintString() { return hintString; }
Sets the hint to apply.
Params:
  • hint – a document describing the index which should be used for this operation.
Returns:this
/** * Sets the hint to apply. * * @param hint a document describing the index which should be used for this operation. * @return this */
public CountOptions hint(@Nullable final Bson hint) { this.hint = hint; return this; }
Sets the hint to apply.
Params:
  • hint – the name of the index which should be used for the operation
Returns:this
Deprecated:Prefer hint(Bson)
/** * Sets the hint to apply. * * @param hint the name of the index which should be used for the operation * @return this * @deprecated Prefer {@link #hint(Bson)} */
@Deprecated public CountOptions hintString(@Nullable final String hint) { this.hintString = hint; return this; }
Gets the limit to apply. The default is 0, which means there is no limit.
Returns:the limit
@mongodb.driver.manualreference/method/cursor.limit/#cursor.limit Limit
/** * Gets the limit to apply. The default is 0, which means there is no limit. * * @return the limit * @mongodb.driver.manual reference/method/cursor.limit/#cursor.limit Limit */
public int getLimit() { return limit; }
Sets the limit to apply.
Params:
  • limit – the limit
Returns:this
@mongodb.driver.manualreference/method/cursor.limit/#cursor.limit Limit
/** * Sets the limit to apply. * * @param limit the limit * @return this * @mongodb.driver.manual reference/method/cursor.limit/#cursor.limit Limit */
public CountOptions limit(final int limit) { this.limit = limit; return this; }
Gets the number of documents to skip. The default is 0.
Returns:the number of documents to skip
@mongodb.driver.manualreference/method/cursor.skip/#cursor.skip Skip
/** * Gets the number of documents to skip. The default is 0. * * @return the number of documents to skip * @mongodb.driver.manual reference/method/cursor.skip/#cursor.skip Skip */
public int getSkip() { return skip; }
Sets the number of documents to skip.
Params:
  • skip – the number of documents to skip
Returns:this
@mongodb.driver.manualreference/method/cursor.skip/#cursor.skip Skip
/** * Sets the number of documents to skip. * * @param skip the number of documents to skip * @return this * @mongodb.driver.manual reference/method/cursor.skip/#cursor.skip Skip */
public CountOptions skip(final int skip) { this.skip = skip; return this; }
Gets the maximum execution time on the server for this operation. The default is 0, which places no limit on the execution time.
Params:
  • timeUnit – the time unit to return the result in
Returns:the maximum execution time in the given time unit
/** * Gets the maximum execution time on the server for this operation. The default is 0, which places no limit on the execution time. * * @param timeUnit the time unit to return the result in * @return the maximum execution time in the given time unit */
public long getMaxTime(final TimeUnit timeUnit) { notNull("timeUnit", timeUnit); return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS); }
Sets the maximum execution time on the server for this operation.
Params:
  • maxTime – the max time
  • timeUnit – the time unit, which may not be null
Returns:this
/** * Sets the maximum execution time on the server for this operation. * * @param maxTime the max time * @param timeUnit the time unit, which may not be null * @return this */
public CountOptions maxTime(final long maxTime, final TimeUnit timeUnit) { notNull("timeUnit", timeUnit); this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit); return this; }
Returns the collation options
Returns:the collation options
Since:3.4
@mongodb.server.release3.4
/** * Returns the collation options * * @return the collation options * @since 3.4 * @mongodb.server.release 3.4 */
@Nullable public Collation getCollation() { return collation; }
Sets the collation options

A null value represents the server default.

Params:
  • collation – the collation options to use
Returns:this
Since:3.4
@mongodb.server.release3.4
/** * Sets the collation options * * <p>A null value represents the server default.</p> * @param collation the collation options to use * @return this * @since 3.4 * @mongodb.server.release 3.4 */
public CountOptions collation(@Nullable final Collation collation) { this.collation = collation; return this; } @Override public String toString() { return "CountOptions{" + "hint=" + hint + ", hintString='" + hintString + '\'' + ", limit=" + limit + ", skip=" + skip + ", maxTimeMS=" + maxTimeMS + ", collation=" + collation + '}'; } }