forked from samus/mongodb-csharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mongo.cs
80 lines (70 loc) · 2.34 KB
/
Mongo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using MongoDB.Driver.Connections;
namespace MongoDB.Driver
{
/// <summary>
/// Description of Mongo.
/// </summary>
public class Mongo : IDisposable
{
private Connection connection;
/// <summary>
/// Initializes a new instance of the <see cref="Mongo"/> class.
/// </summary>
public Mongo () : this(string.Empty){
}
/// <summary>
/// Initializes a new instance of the <see cref="Mongo"/> class.
/// </summary>
/// <param name="connectionString">The connection string.</param>
public Mongo (string connectionString){
if (connectionString == null)
throw new ArgumentNullException ("connectionString");
connection = ConnectionFactory.GetConnection (connectionString);
}
/// <summary>
/// Gets the connection string.
/// </summary>
/// <value>The connection string.</value>
public string ConnectionString {
get { return connection.ConnectionString; }
}
/// <summary>
/// Gets the named database.
/// </summary>
/// <param name="name">The name.</param>
/// <returns></returns>
public Database GetDatabase (String name){
return new Database (connection, name);
}
/// <summary>
/// Gets the <see cref="MongoDB.Driver.Database"/> with the specified name.
/// </summary>
/// <value></value>
public Database this[String name] {
get { return this.GetDatabase (name); }
}
/// <summary>
/// Connects this instance.
/// </summary>
/// <returns></returns>
public Boolean Connect (){
connection.Open ();
return connection.State == ConnectionState.Opened;
}
/// <summary>
/// Disconnects this instance.
/// </summary>
/// <returns></returns>
public Boolean Disconnect (){
connection.Close ();
return connection.State == ConnectionState.Closed;
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose (){
connection.Dispose ();
}
}
}