本文整理汇总了C#中MongoServer类的典型用法代码示例。如果您正苦于以下问题:C# MongoServer类的具体用法?C# MongoServer怎么用?C# MongoServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoServer类属于命名空间,在下文中一共展示了MongoServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public void Setup()
{
server = MongoServer.Create();
server.Connect();
database = server["onlinetests"];
collection = database["testcollection"];
}
示例2: FillDataForUser
public static void FillDataForUser(MongoServer mongosvr)
{
MongoDatabase mongodb = mongosvr.GetDatabase("mongodb");
MongoCollection<BsonDocument> mongoJsCol = mongodb.GetCollection<BsonDocument>("system.js");
mongoJsCol.Insert<BsonDocument>(
new BsonDocument().Add("_id", "sum")
.Add("value", "function (x, y) { return x + y; }"));
MongoGridFS mongofs = mongodb.GetGridFS(new MongoGridFSSettings());
MongoCollection<User> mongoCol = mongodb.GetCollection<User>("User");
mongoCol.RemoveAll();
Random Ro = new Random();
///HugeData
for (int i = 0; i < 1000; i++)
{
mongoCol.Insert(new User()
{
ID = i.ToString(),
Name = "Tom",
Age = (byte)Ro.Next(100),
Age2 = (byte)Ro.Next(100),
Age3 = (byte)Ro.Next(100),
address = new Address()
{
street = "123 Main St.",
City = "Centerville",
state = "PA",
Zip = Ro.Next(20)
}
});
}
}
示例3: Setup
public void Setup()
{
server = MongoServer.Create();
server.Connect();
server.DropDatabase("onlinetests");
database = server["onlinetests"];
}
示例4: AddToReplsetServer
//Replica Set Commands
//http://www.mongodb.org/display/DOCS/Replica+Set+Commands
//rs.help() show help
//rs.status() { replSetGetStatus : 1 }
//rs.initiate() { replSetInitiate : null } initiate
// with default settings
//rs.initiate(cfg) { replSetInitiate : cfg }
//rs.add(hostportstr) add a new member to the set
//rs.add(membercfgobj) add a new member to the set
//rs.addArb(hostportstr) add a new member which is arbiterOnly:true
//rs.remove(hostportstr) remove a member (primary, secondary, or arbiter) from the set
//rs.stepDown() { replSetStepDown : true }
//rs.conf() return configuration from local.system.replset
//db.isMaster() check who is primary
/// <summary>
/// 增加服务器
/// </summary>
/// <param name="mongoSvr">副本组主服务器</param>
/// <param name="HostPort">服务器信息</param>
/// <param name="IsArb">是否为仲裁服务器</param>
/// <returns></returns>
public static CommandResult AddToReplsetServer(MongoServer mongoSvr, String HostPort, int priority, Boolean IsArb)
{
CommandResult mCommandResult = new CommandResult(new BsonDocument());
try
{
if (!IsArb)
{
mCommandResult = ExecuteJsShell("rs.add({_id:" + mongoSvr.Instances.Length + 1 + ",host:'" + HostPort + "',priority:" + priority.ToString() + "});", mongoSvr);
}
else
{
//其实addArb最后也只是调用了add方法
mCommandResult = ExecuteJsShell("rs.addArb('" + HostPort + "');", mongoSvr);
}
}
catch (EndOfStreamException)
{
}
catch (Exception ex)
{
throw ex;
}
return mCommandResult;
}
示例5: Setup
public void Setup()
{
server = MongoServer.Create("mongodb://localhost/?safe=true");
server.Connect();
database = server["onlinetests"];
collection = database["testcollection"];
}
示例6: Server
public Server(string connectionString, string databaseName)
{
this.m_ConnectionString = connectionString;
this.m_MongoClient = new MongoClient(this.m_ConnectionString);
this.m_MongoServer = this.m_MongoClient.GetServer();
this.m_MongoDatabase = this.m_MongoServer.GetDatabase(databaseName);
}
示例7: TestFixtureSetup
public void TestFixtureSetup()
{
server = MongoServer.Create("mongodb://localhost/?safe=true");
database = server["onlinetests"];
collection = database["testcollection"];
collection.Drop();
}
示例8: MongoImpl
public MongoImpl(MongoServer connection, WriteConcern writeConcern)
{
this.writeConcern = writeConcern;
Helpers.Random.Value.NextBytes(initialValue);
collection =
connection.GetDatabase(typeof (SomeDocument).Name).GetCollection<SomeDocument>(typeof (SomeDocument).Name);
}
示例9: Setup
public void Setup()
{
_server = MongoServer.Create("mongodb://localhost/?safe=true");
_server.Connect();
_database = _server["onlinetests"];
_collection = _database["linqtests"];
}
示例10: PersonRepository
public PersonRepository()
{
string connectionString = "mongodb://localhost";
_server = MongoServer.Create(connectionString);
_peopleDb = _server.GetDatabase("Mono");
_people = _peopleDb.GetCollection<Person>("Person");
}
示例11: ExtendedMongoDBCheck
public ExtendedMongoDBCheck(string connectionString, bool isReplSet, bool dbStats)
{
_isReplSet = isReplSet;
_dbStats = dbStats;
if (connectionString.Contains("mongodb://"))
{
_mongoServer = MongoServer.Create(string.Format("{0}{1}?slaveok=true", connectionString, connectionString.EndsWith("/") ? "" : "/"));
}
else
{
MongoServerSettings settings = new MongoServerSettings();
if (connectionString.Contains(":"))
{
string[] bits = connectionString.Split(':');
settings.Server = new MongoServerAddress(bits[0], Convert.ToInt32(bits[1]));
}
else
{
settings.Server = new MongoServerAddress(connectionString);
}
settings.SlaveOk = true;
_mongoServer = MongoServer.Create(settings);
}
}
示例12: EnableSharding
/// <summary>
/// 数据库分片
/// </summary>
/// <param name="routeSvr"></param>
/// <param name="shardingDB"></param>
/// <returns></returns>
public static CommandResult EnableSharding(MongoServer routeSvr, String shardingDB)
{
CommandDocument mongoCmd = new CommandDocument();
mongoCmd = new CommandDocument();
mongoCmd.Add("enablesharding", shardingDB);
return ExecuteMongoCommand(mongoCmd, routeSvr);
}
示例13: DirectConnector
internal DirectConnector(
MongoServer server,
int connectionAttempt
) {
this.server = server;
this.connectionAttempt = connectionAttempt;
}
示例14: TestFixtureSetUp
public void TestFixtureSetUp()
{
_server = MongoServer.Create(ConnStr);
if (_server.DatabaseExists(PropSetCollectionsDb))
_server.DropDatabase(PropSetCollectionsDb);
_testDb = _server.GetDatabase(PropSetCollectionsDb);
}
示例15: TestFixtureSetup
public void TestFixtureSetup()
{
_server = Configuration.TestServer;
_database = Configuration.TestDatabase;
_collection = Configuration.TestCollection;
_collection.Drop();
}