/* Copyright 2018-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.Threading; using System.Threading.Tasks; using MongoDB.Bson; using MongoDB.Driver.Core.Misc; namespace MongoDB.Driver { /// /// Extension methods on IMongoDatabase. /// public static class IMongoDatabaseExtensions { /// /// Watches changes on all collection in a database. /// /// The database. /// The options. /// The cancellation token. /// /// A change stream. /// public static IAsyncCursor> Watch( this IMongoDatabase database, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(database, nameof(database)); var emptyPipeline = new EmptyPipelineDefinition>(); return database.Watch(emptyPipeline, options, cancellationToken); } /// /// Watches changes on all collection in a database. /// /// The database. /// The session. /// The options. /// The cancellation token. /// /// A change stream. /// public static IAsyncCursor> Watch( this IMongoDatabase database, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(database, nameof(database)); Ensure.IsNotNull(session, nameof(session)); var emptyPipeline = new EmptyPipelineDefinition>(); return database.Watch(session, emptyPipeline, options, cancellationToken); } /// /// Watches changes on all collection in a database. /// /// The database. /// The options. /// The cancellation token. /// /// A change stream. /// public static Task>> WatchAsync( this IMongoDatabase database, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(database, nameof(database)); var emptyPipeline = new EmptyPipelineDefinition>(); return database.WatchAsync(emptyPipeline, options, cancellationToken); } /// /// Watches changes on all collection in a database. /// /// The database. /// The session. /// The options. /// The cancellation token. /// /// A change stream. /// public static Task>> WatchAsync( this IMongoDatabase database, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(database, nameof(database)); Ensure.IsNotNull(session, nameof(session)); var emptyPipeline = new EmptyPipelineDefinition>(); return database.WatchAsync(session, emptyPipeline, options, cancellationToken); } } }