• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MongoServer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MongoServer的典型用法代码示例。如果您正苦于以下问题:C# MongoServer类的具体用法?C# MongoServer怎么用?C# MongoServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoServer类属于命名空间,在下文中一共展示了MongoServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Setup

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


示例16: HugRepository

 public HugRepository(string connectionString, string databaseName, IUserProfileRepository userProfileRepository)
 {
     _userProfileRepository = userProfileRepository;
     _server = MongoServer.Create(connectionString);
     _database = _server.GetDatabase(databaseName);
     _mongoCollection = _database.GetCollection<PenedatingMongoUser>("users");
 }
开发者ID:stawiu,项目名称:penedating,代码行数:7,代码来源:HugRepository.cs


示例17: MultipleInstanceMongoServerProxy

        /// <summary>
        /// Initializes a new instance of the <see cref="ShardedMongoServerProxy"/> class.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="instances">The instances.</param>
        /// <param name="connectionQueue">The state change queue.</param>
        /// <param name="connectionAttempt">The connection attempt.</param>
        /// <remarks>This constructor is used when the instances have already been instructed to connect.</remarks>
        protected MultipleInstanceMongoServerProxy(MongoServer server, IEnumerable<MongoServerInstance> instances, BlockingQueue<MongoServerInstance> connectionQueue, int connectionAttempt)
        {
            _state = MongoServerState.Connecting;
            _server = server;
            _connectedInstances = new ConnectedInstanceCollection();
            _connectionAttempt = connectionAttempt;

            _outstandingInstanceConnections = connectionQueue.Count;
            ThreadPool.QueueUserWorkItem(_ =>
            {
                while (connectionQueue.Count > 0)
                {
                    var instance = connectionQueue.Dequeue();
                    Interlocked.Decrement(ref _outstandingInstanceConnections);
                }
            });

            // It's important to have our own copy of this list because it might get modified during iteration. 
            _instances = instances.ToList();
            foreach (var instance in instances)
            {
                instance.StateChanged += InstanceStateChanged;
                ProcessInstanceStateChange(instance);
            }
        }
开发者ID:nickgervasi,项目名称:mongo-csharp-driver,代码行数:33,代码来源:MultipleInstanceMongoServerProxy.cs


示例18: MongoContext

 public MongoContext(string connectionString)
 {
     this.connectionString = connectionString;
     this.server = MongoServer.Create(this.connectionString);
     string databaseName = GetDatabaseName(this.connectionString);
     this.database = server.GetDatabase(databaseName);
 }
开发者ID:scbond,项目名称:MongOData,代码行数:7,代码来源:MongoContext.cs


示例19: TestFixtureSetup

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


示例20: Setup

 public void Setup()
 {
     _server = Configuration.TestServer;
     _primary = Configuration.TestServer.Primary;
     _database = Configuration.TestDatabase;
     _database.Drop();
 }
开发者ID:KeithLee208,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoDatabaseTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MongoServerAddress类代码示例发布时间:2022-05-24
下一篇:
C# MongoRepository类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap