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


C# IMongoClient.GetDatabase方法代码示例

本文整理汇总了C#中IMongoClient.GetDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoClient.GetDatabase方法的具体用法?C# IMongoClient.GetDatabase怎么用?C# IMongoClient.GetDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMongoClient的用法示例。


在下文中一共展示了IMongoClient.GetDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BookContext

        public BookContext(IMongoClient mc)
        {
            //Connecting to local
            client = mc;

            this.db = client.GetDatabase("bookStore");
        }
开发者ID:cesaroll,项目名称:MongoDb_C-Net_BookApp,代码行数:7,代码来源:BookContext.cs

示例2: DistrictsRepository

        public DistrictsRepository(IMongoClient client, string database)
        {
            // todo: move this out to IOC config
            var cp = new ConventionPack();
            cp.Add(new CamelCaseElementNameConvention());
            ConventionRegistry.Register("camel case", cp, x => true);

            _client = client;
            _db = _client.GetDatabase(database);
            _collection = _db.GetCollection<District>("districts");
        }
开发者ID:tbehunin,项目名称:kulepool,代码行数:11,代码来源:DistrictsRepository.cs

示例3: maplistcontent

        public async Task<HttpResponseMessage> maplistcontent(string area)
        {


            _mongoClient = new MongoClient(ConfigurationManager.ConnectionStrings["MongoDBContext"].ConnectionString);
            _mongoDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["civilgisDBname"]);

            //_mongoDatabase.ListCollectionsAsync
           // List<BsonDocument> list = _mongoDatabase.ListCollectionsAsync().Result.ToListAsync().Result;

            string result = "[";
            int count = 0;
            area = area + "_";
            using (var cursor = await _mongoDatabase.ListCollectionsAsync())
            {
                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var bsonDocument in batch)
                    {
                        var _collection_nm = bsonDocument.GetValue("name");
                        
                        
                        string rd = _collection_nm.ToString();

                        if (rd.Contains(area) == true)
                        {
                            // output format: [[1,"oc_address"],[2,"oc_bounds"],[3,"oc_cities"],[4,"oc_education_facility"],[5,"oc_fire_grid"],[6,"oc_fire_stations"],[7,"oc_hospitals"],[8,"oc_hwy_majorrd"],[9,"oc_rails"],[10,"oc_streets"],[11,"oc_water"]]

                            count++;
                            result = result + '[' + Convert.ToString(count)+ ',' + '"' +rd + '"' +"],";
                            
                        }//if
                    }
                }



            }// using

            // remove last ","
            result = result.Remove(result.Length - 1);

            result = result + "]";



            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result, "text/plain");



            return response;

        }
开发者ID:hoogw,项目名称:civilgis_net_1,代码行数:54,代码来源:GeojsonController.cs

示例4: GetMongoDatabase

 static IMongoDatabase GetMongoDatabase(IMongoClient mongoClient)
 {
     var url = GetUrl();
     var settings = new MongoDatabaseSettings
     {
         GuidRepresentation = GuidRepresentation.Standard,
         WriteConcern = WriteConcern.Acknowledged
     };
     var mongoDatabase = mongoClient.GetDatabase(url.DatabaseName, settings);
     return mongoDatabase;
 }
开发者ID:nls75,项目名称:Rebus,代码行数:11,代码来源:MongoTestHelper.cs

示例5: MongoDbRepository

        public MongoDbRepository(IOptions<AppSettings> appSettings)
        {
            _client = new MongoClient(appSettings.Value.MongoDbConnectionString);
            _database = _client.GetDatabase(appSettings.Value.MongoDbName);

            _tweetCollection = _database.GetCollection<Tweet>("tweets");
            _userFollowsCollection = _database.GetCollection<UserFollows>("user_follows");
            _userLikesCollection = _database.GetCollection<UserLikes>("user_likes");
            _conversationCollection = _database.GetCollection<Conversation>("conversations");
            _userNotificationCollection = _database.GetCollection<UserNotifications>("user_notifications");
        }
开发者ID:kristersz,项目名称:Tweetus,代码行数:11,代码来源:MongoDbRepository.cs

示例6: MongoDBManager

 public MongoDBManager()
 {
     _mongoClient = new MongoClient(ConfigurationManager.ConnectionStrings["DrustveneMrezeConnectionString"].ConnectionString);
     _mongoUserInfoDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["DrustveneMrezeDatabaseName"]);
     _mongoMoviesDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["DrustveneMrezeMoviesDatabaseName"]);
     _mongoTweetsDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["DrustveneMrezeTweetsDatabaseName"]);
     
 }
开发者ID:Kaca992,项目名称:DrustveneMreze,代码行数:8,代码来源:MongoDBManager.cs

示例7: InsertMongoDb

        public static void InsertMongoDb()
        {
            try
            {
                _client = new MongoClient();
                _database = _client.GetDatabase("test");

                var document = new BsonDocument
                {
                    {
                        "Utilisateur", new BsonDocument
                        {
                            {"id", "1"},
                            {"nom", "LAMGHARI"},
                            {"prenom", "Mohammed"},
                            {"mail", "mail"},
                            {"pseudo", "dskat747"},
                            {"mdp", "1234"},
                            {"handicap", "false"},
                            {
                                "ProfileParking", new BsonDocument
                                {
                                    {"id", "2"},
                                    {"profil", "admin"}
                                }
                            },
                            {"Reservation", new BsonDocument
                                {
                                    {"id", "15"},
                                    {"Place", new BsonDocument
                                                    {
                                                        {"id", "1"},
                                                        {"profile", "admin"},
                                                        {"mac_address", "DF,15,21,DF,00"},
                                                        {"nom", "place 01"},
                                                        {"Parking", new BsonDocument
                                                                            {
                                                                                {"adresse", "Valenciennes"},
                                                                                {"NbPlace", "150"},
                                                                                {"etat", "Operationnel"}
                                                                            }
                                                        }
                                                    }
                                    }
                                }
                            }
                        }
                    }
                };

                var collection = _database.GetCollection<BsonDocument>("test");
                //collection.InsertOne(document);


            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:dimafoot,项目名称:EBusiness2,代码行数:60,代码来源:Program.cs

示例8: DataStore

        private DataStore(string databaseName, MongoDatabaseSettings settings = null)
        {
            _client = new MongoClient();
            _database = _client.GetDatabase(databaseName, settings);

            DatabaseName = databaseName;
        }
开发者ID:mingezhao,项目名称:PersonalTools,代码行数:7,代码来源:DataStore.cs

示例9: DefaultController

 public DefaultController() {
     _client = new MongoClient(new MongoClientSettings
     {
         Server = new MongoServerAddress("localhost", 27017)
     });
     _database = _client.GetDatabase("test");
 }
开发者ID:jmistx,项目名称:MongoAspTemplate,代码行数:7,代码来源:DefaultController.cs

示例10: DocumentDb

 public DocumentDb(string DBName,ISchemaContext SchemaContext)
 {
     _client = new MongoClient();
     _database = _client.GetDatabase(DBName);
     ctx = SchemaContext;
     this.DBName = DBName;
 }
开发者ID:anwarminarso,项目名称:IDLake,代码行数:7,代码来源:DocumentDb.cs

示例11: GameRepository

 public GameRepository()
 {
     string connection = System.Configuration.ConfigurationManager.ConnectionStrings["Mongodb"].ConnectionString;
     _client = new MongoClient(connection);
     _database = _client.GetDatabase(System.Configuration.ConfigurationManager.AppSettings["DataBaseName"]);
     _collection = _database.GetCollection<GameEntity>("games");
 }
开发者ID:sheldonaj,项目名称:blackjackASP,代码行数:7,代码来源:GameRepository.cs

示例12: getMongoDB

 public static IMongoDatabase getMongoDB()
 {
     _client = new MongoClient("mongodb://145.24.222.168/CityGis"); //Connection string gaat hier
     //_client = new MongoClient("mongodb://localhost/CityGis");
     _database = _client.GetDatabase("CityGis");
     return _database;
 }
开发者ID:ChuckTenton,项目名称:CityGist-Project-56,代码行数:7,代码来源:DatabaseConnection.cs

示例13: Main

        public static void Main(string[] args)
        {
            // #Connect to Db Shop => caseSensitive!!!
            client = new MongoClient("mongodb://127.0.0.1");
            database = client.GetDatabase("Shop");

            //var eDrink = new EnergyDrink("Hell", 1.05);

            // #connect to table EnergyDrinks
            var drinksCollection = database.GetCollection<EnergyDrink>("EnergyDrinks");

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Enter command:");
                Console.WriteLine("Add new drink: => 1");
                Console.WriteLine("Get all drinks: => 2");
                Console.WriteLine("Get drinks by name => 3");
                Console.WriteLine("Get drinks by price => 4");

                var command = Console.ReadLine();

                switch (command)
                {
                    case "1": InsertToDatabase(drinksCollection); break;
                    case "2": GetAllDrinks(drinksCollection); break;
                    case "3": SearchByName(drinksCollection); break;
                    case "4": SearchByPrice(drinksCollection); break;
                    default:
                        break;
                }
            }
        }
开发者ID:ni4ka7a,项目名称:TelerikAcademyHomeworks,代码行数:33,代码来源:EntryPoint.cs

示例14: DatabaseContext

 static DatabaseContext()
 {
     //var connectionString = ConfigurationManager.ConnectionStrings[CONNECTION_STRING_NAME].ConnectionString;
     var connectionString = "mongodb://dbadmin:[email protected]:55722/edubase";
     _client = new MongoClient(connectionString);
     _database = _client.GetDatabase(DATABASE_NAME);
 }
开发者ID:wadim1611,项目名称:CourseBuildingsSystemMVCandWCF,代码行数:7,代码来源:DatabaseContext.cs

示例15: MongoConnection

        public static IMongoDatabase MongoConnection() {

            client = new MongoClient("mongodb://145.24.222.117/Planetis3");
            database = client.GetDatabase("Planetis3");

            return database;

        }
开发者ID:SnipSnapper,项目名称:WebApplication,代码行数:8,代码来源:DBConnection.cs


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