IMongoClient.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright 2013-2016 MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using MongoDB.Bson;
  18. using MongoDB.Driver.Core.Clusters;
  19. namespace MongoDB.Driver
  20. {
  21. /// <summary>
  22. /// The client interface to MongoDB.
  23. /// </summary>
  24. /// <remarks>
  25. /// This interface is not guaranteed to remain stable. Implementors should use
  26. /// <see cref="MongoClientBase"/>.
  27. /// </remarks>
  28. public interface IMongoClient
  29. {
  30. /// <summary>
  31. /// Gets the cluster.
  32. /// </summary>
  33. /// <value>
  34. /// The cluster.
  35. /// </value>
  36. ICluster Cluster { get; }
  37. /// <summary>
  38. /// Gets the settings.
  39. /// </summary>
  40. MongoClientSettings Settings { get; }
  41. /// <summary>
  42. /// Drops the database with the specified name.
  43. /// </summary>
  44. /// <param name="name">The name of the database to drop.</param>
  45. /// <param name="cancellationToken">The cancellation token.</param>
  46. void DropDatabase(string name, CancellationToken cancellationToken = default(CancellationToken));
  47. /// <summary>
  48. /// Drops the database with the specified name.
  49. /// </summary>
  50. /// <param name="name">The name of the database to drop.</param>
  51. /// <param name="cancellationToken">The cancellation token.</param>
  52. /// <returns>A task.</returns>
  53. Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
  54. /// <summary>
  55. /// Gets a database.
  56. /// </summary>
  57. /// <param name="name">The name of the database.</param>
  58. /// <param name="settings">The database settings.</param>
  59. /// <returns>An implementation of a database.</returns>
  60. IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null);
  61. /// <summary>
  62. /// Lists the databases on the server.
  63. /// </summary>
  64. /// <param name="cancellationToken">The cancellation token.</param>
  65. /// <returns>A cursor.</returns>
  66. IAsyncCursor<BsonDocument> ListDatabases(CancellationToken cancellationToken = default(CancellationToken));
  67. /// <summary>
  68. /// Lists the databases on the server.
  69. /// </summary>
  70. /// <param name="cancellationToken">The cancellation token.</param>
  71. /// <returns>A Task whose result is a cursor.</returns>
  72. Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(CancellationToken cancellationToken = default(CancellationToken));
  73. /// <summary>
  74. /// Returns a new IMongoClient instance with a different read concern setting.
  75. /// </summary>
  76. /// <param name="readConcern">The read concern.</param>
  77. /// <returns>A new IMongoClient instance with a different read concern setting.</returns>
  78. IMongoClient WithReadConcern(ReadConcern readConcern);
  79. /// <summary>
  80. /// Returns a new IMongoClient instance with a different read preference setting.
  81. /// </summary>
  82. /// <param name="readPreference">The read preference.</param>
  83. /// <returns>A new IMongoClient instance with a different read preference setting.</returns>
  84. IMongoClient WithReadPreference(ReadPreference readPreference);
  85. /// <summary>
  86. /// Returns a new IMongoClient instance with a different write concern setting.
  87. /// </summary>
  88. /// <param name="writeConcern">The write concern.</param>
  89. /// <returns>A new IMongoClient instance with a different write concern setting.</returns>
  90. IMongoClient WithWriteConcern(WriteConcern writeConcern);
  91. }
  92. }