当前位置: 首页>>代码示例>>C#>>正文


C# MongoServer类代码示例

本文整理汇总了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"];
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoCollectionTests.cs

示例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)
                    }
                });
            }
        }
开发者ID:avatasia,项目名称:MagicMongoDBTool,代码行数:32,代码来源:InitTestData.cs

示例3: Setup

 public void Setup()
 {
     server = MongoServer.Create();
     server.Connect();
     server.DropDatabase("onlinetests");
     database = server["onlinetests"];
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoDatabaseTests.cs

示例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;
        }
开发者ID:qq33357486,项目名称:MagicMongoDBTool,代码行数:46,代码来源:MongoDBHelper_RunCommand.cs

示例5: Setup

 public void Setup()
 {
     server = MongoServer.Create("mongodb://localhost/?safe=true");
     server.Connect();
     database = server["onlinetests"];
     collection = database["testcollection"];
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoCollectionTests.cs

示例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);
 }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:7,代码来源:Server.cs

示例7: TestFixtureSetup

 public void TestFixtureSetup()
 {
     server = MongoServer.Create("mongodb://localhost/?safe=true");
     database = server["onlinetests"];
     collection = database["testcollection"];
     collection.Drop();
 }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:7,代码来源:CSharp282Tests.cs

示例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);
		}
开发者ID:undeadcat,项目名称:mongobenchmark,代码行数:7,代码来源:MongoImpl.cs

示例9: Setup

 public void Setup()
 {
     _server = MongoServer.Create("mongodb://localhost/?safe=true");
     _server.Connect();
     _database = _server["onlinetests"];
     _collection = _database["linqtests"];
 }
开发者ID:moonreplace,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoQueryableTests.cs

示例10: PersonRepository

 public PersonRepository()
 {
     string connectionString = "mongodb://localhost";
     _server = MongoServer.Create(connectionString);
     _peopleDb = _server.GetDatabase("Mono");
     _people = _peopleDb.GetCollection<Person>("Person");
 }
开发者ID:henryoswald,项目名称:MongoNancyMono,代码行数:7,代码来源:PersonRepository.cs

示例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);
            }
        }
开发者ID:MYJDMCIVICEM2,项目名称:sd-agent-windows,代码行数:25,代码来源:ExtendedMongoDBCheck.cs

示例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);
 }
开发者ID:kklik,项目名称:MagicMongoDBTool,代码行数:13,代码来源:MongoDBHelper_Replset.cs

示例13: DirectConnector

 internal DirectConnector(
     MongoServer server,
     int connectionAttempt
 ) {
     this.server = server;
     this.connectionAttempt = connectionAttempt;
 }
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:7,代码来源:DirectConnector.cs

示例14: TestFixtureSetUp

 public void TestFixtureSetUp()
 {
     _server = MongoServer.Create(ConnStr);
     if (_server.DatabaseExists(PropSetCollectionsDb))
         _server.DropDatabase(PropSetCollectionsDb);
     _testDb = _server.GetDatabase(PropSetCollectionsDb);
 }
开发者ID:KlaudWerk,项目名称:WSHumanTask,代码行数:7,代码来源:MongoPropertySchemaSetTest.cs

示例15: TestFixtureSetup

 public void TestFixtureSetup()
 {
     _server = Configuration.TestServer;
     _database = Configuration.TestDatabase;
     _collection = Configuration.TestCollection;
     _collection.Drop();
 }
开发者ID:annikulin,项目名称:code-classifier,代码行数:7,代码来源:CSharp282Tests.cs


注:本文中的MongoServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。