forked from samus/mongodb-csharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mongo.cs
78 lines (65 loc) · 2.25 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
/*
* User: scorder
* Date: 7/7/2009
*/
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace MongoDB.Driver
{
/// <summary>
/// Description of Mongo.
/// </summary>
public class Mongo
{
private Connection connection;
private String host;
public string Host {
get { return host; }
set { host = value; }
}
private int port;
public int Port {
get { return port; }
set { port = value; }
}
/// <summary>
/// Creates the object with the default localhost:27017 parameters. The connection is
/// created lazily.
/// </summary>
public Mongo():this(Connection.DEFAULTHOST,Connection.DEFAULTPORT)
{
}
public Mongo(String host):this(host,Connection.DEFAULTPORT){
}
public Mongo(String host, int port){
this.Host = host;
this.port = port;
connection = new Connection(host, port);
}
public Mongo(String leftHost, String rightHost):this(leftHost,Connection.DEFAULTPORT,rightHost,Connection.DEFAULTPORT,false){}
public Mongo(String leftHost, int leftPort, String rightHost, int rightPort):this(leftHost,leftPort,rightHost,rightPort,false){}
public Mongo(String leftHost, int leftPort, String rightHost, int rightPort, bool slaveOk){
this.Host = leftHost;
this.port = leftPort;
connection = new PairedConnection(leftHost,leftPort,rightHost,rightPort,slaveOk);
}
public Database getDB(String name){
return new Database(connection, name);
}
public Database this[ String name ] {
get{
return this.getDB(name);
}
}
public Boolean Connect(){
connection.Open();
return connection.State == ConnectionState.Opened;
}
public Boolean Disconnect(){
connection.Close();
return connection.State == ConnectionState.Closed;
}
}
}