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

C# Driver.MongoClient类代码示例

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

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



MongoClient类属于MongoDB.Driver命名空间,在下文中一共展示了MongoClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetMongoContext

 public MongoDatabase GetMongoContext()
 {
     MongoClient client = new MongoClient(path);
     MongoServer server = client.GetServer();
     MongoDatabase dbContext = server.GetDatabase("mongotelerikchat");
     return dbContext;
 }
开发者ID:Varbanov,项目名称:TelerikAcademy,代码行数:7,代码来源:MongoChat.xaml.cs


示例2: IsRestored

    public bool IsRestored(string connectionName)
    {
      MongoServer server = null;
      var connectionString = ConfigurationManager.ConnectionStrings[connectionName]?.ConnectionString;

      if (string.IsNullOrEmpty(connectionString))
      {
        return false;
      }

      try
      {
        var mongoUrl = new MongoUrl(connectionString);
        var mongoClient = new MongoClient(mongoUrl);
        server = mongoClient.GetServer();

        return server.GetDatabase(mongoUrl.DatabaseName).CollectionExists(MongoRestoreSettings.RestoredDbTokenCollection);
      }
      catch (FormatException ex)
      {
        Log.Error("Wrong connection string format", ex, this);
        throw;
      }
      finally
      {
        server?.Disconnect();
      }
    }
开发者ID:kamsar,项目名称:Habitat,代码行数:28,代码来源:MongoRestoreService.cs


示例3: MongoContext

        public MongoContext()
        {
            var client = new MongoClient(ConfigurationManager.ConnectionStrings[DATABASE].ConnectionString);
            var server = client.GetServer();

            _database = server.GetDatabase(DATABASE);
        }
开发者ID:Beren1h,项目名称:Insight,代码行数:7,代码来源:MongoContext.cs


示例4: PatientRepository

 /// <summary />
 public PatientRepository()
 {
     var client = new MongoClient(ConfigurationManager.ConnectionStrings["Mongo_patientcare_datamock"].ConnectionString);
     _log = new Logger("WebAPI : PatientRepository");
     _db = client.GetDatabase("patientcare_datamock");
     _patients = _db.GetCollection<BsonDocument>("Patients");
 }
开发者ID:dsb92,项目名称:patientcare,代码行数:8,代码来源:PatientRepository.cs


示例5: MongoRepositoryContext

 static MongoRepositoryContext() {
     settings = new MongoRepositorySettings();
     var url = new MongoUrl(ConfigurationManager.ConnectionStrings["SysDB"].ConnectionString);
     client = new MongoClient(url);
     server = client.GetServer();
     database = server.GetDatabase(url.DatabaseName);
 }
开发者ID:wudan330260402,项目名称:Danwu.Core,代码行数:7,代码来源:MongoRepositoryContext.cs


示例6: GetMongoCollection

 private MongoCollection<BsonDocument> GetMongoCollection()
 {
     var client = new MongoClient(_connectionString);
     var db = client.GetServer().GetDatabase(new MongoUrl(_connectionString).DatabaseName);
     var collection = db.GetCollection(_collectionName);
     return collection;
 }
开发者ID:hxzqlh,项目名称:enode,代码行数:7,代码来源:MongoEventPublishInfoStore.cs


示例7: MainAsync

        static async Task MainAsync(string[] args)
        {
            var urlString = "mongodb://localhost:27017";
            var client = new MongoClient(urlString);
            var db = client.GetDatabase("students");
            var collection = db.GetCollection<BsonDocument>("grades");
            var filter = new BsonDocument("type","homework");
           // var count = 0;
            var sort = Builders<BsonDocument>.Sort.Ascending("student_id").Ascending("score");
            var result = await collection.Find(filter).Sort(sort).ToListAsync();
           var previous_id=-1 ;
           var student_id=-1;
            int count = 0;
            foreach (var doc in result)         
            {
                
                student_id = (int)doc["student_id"];
                    //Console.WriteLine(student_id);
                if (student_id != previous_id)
                {
                    count++;
                    previous_id = student_id;
                    Console.WriteLine("removing :{0} ", doc);
                   // await collection.DeleteOneAsync(doc);

                    await collection.DeleteManyAsync(doc);
                }



              // process document
            }
            Console.WriteLine(count);
            //Console.WriteLine(coll.FindAsync<"">);
        }
开发者ID:sahithrao153,项目名称:M101Dotnet,代码行数:35,代码来源:MongoDB.cs


示例8: MongoDbBase

 public MongoDbBase(string connectionString, string database)
 {
     this.connectionString = connectionString;
     this.database = database;
     Client = new MongoClient(connectionString);
     Database = Client.GetDatabase(database);
 }
开发者ID:Flavien,项目名称:mongodb-storage,代码行数:7,代码来源:MongoDbBase.cs


示例9: AddWord

        public async Task<ActionResult> AddWord()
        {
            var client = new MongoClient(_connection);
            var db = client.GetDatabase(_database);

            var words = db.GetCollection<BsonDocument>("Word");

            var word1 = new Word
            {
                Text = "Ape",
                Type = Enums.WordType.Noun.ToString()
            };

            var bsonObject = word1.ToBsonDocument();

            try
            {
                await words.InsertOneAsync(bsonObject);
            }
            catch (Exception ex)
            {
                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }

            return Json("success", JsonRequestBehavior.AllowGet);
        }
开发者ID:kablitz,项目名称:SPRNT,代码行数:26,代码来源:NameGenController.cs


示例10: TodoItemRepository

 public TodoItemRepository(string mongoConnection, string databaseName)
 {
     collectionName = "todoitems";
     var client = new MongoClient(mongoConnection);
     this.database = client.GetDatabase(databaseName);
     this.collection = database.GetCollection<TodoItem>(collectionName);
 }
开发者ID:CedricLeblond,项目名称:MultiChannelTodo,代码行数:7,代码来源:TodoItemRepository.cs


示例11: MongoDbStore

 public static MongoDbWorkflowStore MongoDbStore()
 {
     var client = new MongoClient("mongodb://localhost");
     var server = client.GetServer();
     var database = server.GetDatabase("StatelessWorkflowTest");
     return new MongoDbWorkflowStore(database);
 }
开发者ID:rajeshgupthar,项目名称:Stateless.WorkflowEngine,代码行数:7,代码来源:BootStrapper.cs


示例12: MainAsync

        private async Task MainAsync()
        {
            var connStr = "mongodb://localhost:27017";
            var client = new MongoClient(connStr);
            var db = client.GetDatabase("store");
            var col = db.GetCollection<Product>("products");
            await db.DropCollectionAsync("products");

            Random random = new Random();

            List<string> descriptions = new List<string>() { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj" };
            List<string> categories = new List<string>() { "sports", "food", "clothing", "electronics" };
            List<string> brands = new List<string>() { "GE", "nike", "adidas", "toyota", "mitsubishi" };

            var docs = Enumerable.Range(0, 100)
                .Select(i => new Product
                {
                    Id = i,
                    SKU = String.Format("{0:D8}", i),
                    Price = random.NextDouble() * (100 - 1) + 1,
                    Description = descriptions[random.Next(descriptions.Count)],
                    Category = categories[random.Next(categories.Count)],
                    Brand = brands[random.Next(brands.Count)],
                    Reviews = new List<Review>(),
                });
            await col.InsertManyAsync(docs);

            await col.Indexes.CreateOneAsync(Builders<Product>.IndexKeys.Ascending(x => x.SKU), new CreateIndexOptions() { Unique = true });
            await col.Indexes.CreateOneAsync(Builders<Product>.IndexKeys.Descending(x => x.Price));
            await col.Indexes.CreateOneAsync(Builders<Product>.IndexKeys.Ascending(x => x.Description));
            await col.Indexes.CreateOneAsync(Builders<Product>.IndexKeys.Ascending(x => x.Category).Ascending(x => x.Brand));
            await col.Indexes.CreateOneAsync("{'reviews.author':1}");
        }
开发者ID:azmikamis,项目名称:M101NAssignments,代码行数:33,代码来源:Week4Assignment.cs


示例13: Main

        public static int Main(string[] args)
        {
            var client = new MongoClient("");
            var db = client.GetDatabase("guess-what");
            var templateCollection = db.GetCollection<BsonDocument>("templates");
            // Use this to delete single items or spam:

            // templateCollection.DeleteOne(new BsonDocument(new BsonElement("_id", BsonValue.Create("Zp-ifMYR_0W6D0GwKsuoSw"))));
            // templateCollection.DeleteOne(new BsonDocument(new BsonElement("_id", BsonValue.Create("Ss0ISYQbSEyUsYVnMjbDAw"))));

            /*
            var regex = new Regex("^<a href=\"http://.*#\\d*\">.*</a>,$");
            foreach (var template in templateCollection.Find(new BsonDocument()).ToList())
            {
                var description = template.GetElement("Description").Value.ToString().Trim();
                if (regex.Matches(description).Count > 0)
                {
                    templateCollection.DeleteOne(new BsonDocument (template.GetElement("_id")));
                }
                else
                {
                    Console.WriteLine("OK  :" + description);
                }
            }
            */
            Console.WriteLine("END.");
            Console.ReadLine();
            return 0;
        }
开发者ID:daniel-kun,项目名称:guess-what,代码行数:29,代码来源:Program.cs


示例14: InitMongoDB

        public static bool InitMongoDB(this Funq.Container container)
        {
            try
            {
                // Register the MySql Database Connection Factory
                var mongoDbConnectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString;
                var client = new MongoClient(mongoDbConnectionString);
                var server = client.GetServer();
                var database = server.GetDatabase("hello_world");
                container.Register<MongoDatabase>(c => database);

                BsonClassMap.RegisterClassMap<World>(cm => {
                    cm.MapProperty(c => c.id);
                    cm.MapProperty(c => c.randomNumber);
                });

                BsonClassMap.RegisterClassMap<Fortune>(cm => {
                    cm.MapProperty(c => c.id);
                    cm.MapProperty(c => c.message);
                });

                // Create needed tables in MySql Server if they do not exist
                return database.CreateWorldTable() && database.CreateFortuneTable();
            }
            catch
            {
                // Unregister failed database connection factory
                container.Register<MongoDatabase>(c => null);

                return false;
            }

        }
开发者ID:cmsimike,项目名称:FrameworkBenchmarks,代码行数:33,代码来源:AppHostConfigHelper.cs


示例15: GetDatabase

        public IMongoDatabase GetDatabase()
        {
            var client = new MongoClient(this.ConnectionString);
            var db = client.GetDatabase(this.DatabaseName);

            return db;
        }
开发者ID:ni4ka7a,项目名称:Molybdenum-Team,代码行数:7,代码来源:MongoProvider.cs


示例16: EstablishConnection

 public static void EstablishConnection()
 {
     client = new MongoClient(connectionString);
     server = client.GetServer();
     database = server.GetDatabase(DbName);
     entries = database.GetCollection<JSonReport>(collectionName);
 }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:7,代码来源:MongoDbReportReader.cs


示例17: MongoSystemEventLogger

 /// <summary>
 /// Initializes a new instance of the <see cref="MongoSystemEventLogger"/> class.
 /// </summary>
 /// <param name="configuration">The configuration options.</param>
 public MongoSystemEventLogger(IMongoConfiguration configuration)
 {
     this.Configuration = configuration;
     MongoClient client = new MongoClient(configuration.ToMongoClientSettings());
     this.Server = client.GetServer();
     this.Database = this.Server.GetDatabase(configuration.Database);
 }
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:11,代码来源:MongoSystemEventLogger.cs


示例18: GetCollection

 public static MongoCollection<BsonDocument> GetCollection(string collectionName)
 {
     var mongoclient = new MongoClient(ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString);
         var server = mongoclient.GetServer();
         var MongoDatabase = server.GetDatabase("CVServicePoc");
         return MongoDatabase.GetCollection(collectionName);
 }
开发者ID:brosen,项目名称:CVServicePoc,代码行数:7,代码来源:MongoHelper.cs


示例19: Post

        public void Post(UserModel model)
        {
            var mongoDbClient = new MongoClient("mongodb://127.0.0.1:27017");
            var mongoDbServer = mongoDbClient.GetDatabase("SocialNetworks");
            BsonArray arr = new BsonArray();            
            dynamic jobj = JsonConvert.DeserializeObject<dynamic>(model.Movies.ToString());
            foreach (var item in jobj)
            {
                foreach(var subitem in item)
                {
                    arr.Add(subitem.Title.ToString());
                }
            }

            var document = new BsonDocument
            {
                { "Facebook_ID",  model.Facebook_ID },
                { "Ime",  model.Ime  },
                { "Prezime",  model.Prezime  },
                { "Email",  model.Email  },
                { "DatumRodjenja",  model.DatumRodjenja  },
                { "Hometown", model.Hometown},
                { "ProfilePictureLink", model.ProfilePictureLink  },
                { "Movies",  arr },
            };

            var collection = mongoDbServer.GetCollection<BsonDocument>("UserInfo");
            collection.InsertOneAsync(document);
        }
开发者ID:IvanKresic,项目名称:SocialNetworkRecommander,代码行数:29,代码来源:UserInfoController.cs


示例20: BaseRepository

 public BaseRepository(string collection)
 {
     _collectionName = collection;
     var client = new MongoClient(ConfigurationManager.ConnectionStrings["mongodb"].ConnectionString);
     var db = client.GetServer().GetDatabase(ConfigurationManager.ConnectionStrings["mongodb"].ProviderName);
     _collection = db.GetCollection(_collectionName);
 }
开发者ID:xuantranm,项目名称:DigitalMarket,代码行数:7,代码来源:BaseRepository.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Driver.MongoClientSettings类代码示例发布时间:2022-05-26
下一篇:
C# Driver.FindAndModifyArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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