/* Copyright 2015-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.
*/
using System;
using MongoDB.Bson;
using MongoDB.Driver.Core.Misc;
namespace MongoDB.Driver
{
///
/// Options for a find operation.
///
public abstract class FindOptionsBase
{
// fields
private bool? _allowPartialResults;
private int? _batchSize;
private Collation _collation;
private string _comment;
private CursorType _cursorType;
private TimeSpan? _maxAwaitTime;
private TimeSpan? _maxTime;
private BsonDocument _modifiers;
private bool? _noCursorTimeout;
private bool? _oplogReplay;
// constructors
///
/// Initializes a new instance of the class.
///
public FindOptionsBase()
{
_cursorType = CursorType.NonTailable;
}
// properties
///
/// Gets or sets a value indicating whether to allow partial results when some shards are unavailable.
///
public bool? AllowPartialResults
{
get { return _allowPartialResults; }
set { _allowPartialResults = value; }
}
///
/// Gets or sets the size of a batch.
///
public int? BatchSize
{
get { return _batchSize; }
set { _batchSize = Ensure.IsNullOrGreaterThanOrEqualToZero(value, nameof(value)); }
}
///
/// Gets or sets the collation.
///
public Collation Collation
{
get { return _collation; }
set { _collation = value; }
}
///
/// Gets or sets the comment.
///
public string Comment
{
get { return _comment; }
set { _comment = value; }
}
///
/// Gets or sets the type of the cursor.
///
public CursorType CursorType
{
get { return _cursorType; }
set { _cursorType = value; }
}
///
/// Gets or sets the maximum await time for TailableAwait cursors.
///
public TimeSpan? MaxAwaitTime
{
get { return _maxAwaitTime; }
set { _maxAwaitTime = value; }
}
///
/// Gets or sets the maximum time.
///
public TimeSpan? MaxTime
{
get { return _maxTime; }
set { _maxTime = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(value, nameof(value)); }
}
///
/// Gets or sets the modifiers.
///
public BsonDocument Modifiers
{
get { return _modifiers; }
set { _modifiers = value; }
}
///
/// Gets or sets whether a cursor will time out.
///
public bool? NoCursorTimeout
{
get { return _noCursorTimeout; }
set { _noCursorTimeout = value; }
}
///
/// Gets or sets whether the OplogReplay bit will be set.
///
public bool? OplogReplay
{
get { return _oplogReplay; }
set { _oplogReplay = value; }
}
}
///
/// Options for finding documents.
///
public class FindOptions : FindOptionsBase
{ }
///
/// Options for finding documents.
///
/// The type of the document.
/// The type of the projection (same as TDocument if there is no projection).
public class FindOptions : FindOptionsBase
{
// fields
private int? _limit;
private ProjectionDefinition _projection;
private int? _skip;
private SortDefinition _sort;
// properties
///
/// Gets or sets how many documents to return.
///
public int? Limit
{
get { return _limit; }
set { _limit = value; }
}
///
/// Gets or sets the projection.
///
public ProjectionDefinition Projection
{
get { return _projection; }
set { _projection = value; }
}
///
/// Gets or sets how many documents to skip before returning the rest.
///
public int? Skip
{
get { return _skip; }
set { _skip = value; }
}
///
/// Gets or sets the sort.
///
public SortDefinition Sort
{
get { return _sort; }
set { _sort = value; }
}
}
///
/// Options for finding documents.
///
/// The type of the document and the result.
public class FindOptions : FindOptions
{
}
}