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


C# MongoDatabase.GetCollection方法代码示例

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


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

示例1: Test2

        public static void Test2(MongoDatabase db)
        {
            var d = new Dictionary<string, object>();
            var pp = new PortalPage { Title = "This is my test", Id = "test1" };
            var pc = new PortalPageColumn();
            pp.Columns.Add(pc);
            pc.Config["width"] = 200;
            d["open"] = "open listener";
            d["close"] = "close listener";
            d["interval"] = 500;
            pc.Config["listeners"] = d;

            d = new Dictionary<string, object>();
            d["open"] = "open listener";
            d["close"] = "close listener";
            d["interval"] = 500;
            pc.Config["listeners"] = d;

            var pt = new Portlet { Title = "test portlet 1", PortletClass = "GraphImage" };
            pt.Config["width"] = 200;
            pt.Config["height"] = 300;
            pt.Config["listeners"] = d;
            pc.Portlets.Add(pt);

            db.GetCollection<PortalPage>().Save(pp);

            var pp2 = db.GetCollection<PortalPage>().FindOneById(pp.Id);
            Console.WriteLine("p2: {0}", pp2.Title);
        }
开发者ID:lafar6502,项目名称:cogmon,代码行数:29,代码来源:Program.cs

示例2: ElectionsModule

        public ElectionsModule()
            : base("/elections")
        {
            //setup Mongo
            m_mongoDataBase = MongoServer
                .Create(ConfigurationManager.ConnectionStrings["mongoDbConnectionString"].ConnectionString)
                .GetDatabase("wf1_read_model", SafeMode.False);

            //configure routes

            //return all elections
            Get["/"] = parameters => m_mongoDataBase.GetCollection<ElectionDto>("Elections");

            //return specific election
            Get["/{electionid}"] = parameters =>
                                      {
                                          //todo: content negotiation.
                                          var electionCollection = m_mongoDataBase.GetCollection<ElectionDto>("Elections");
                                          string electionId = parameters.electionid;
                                          var query = Query<ElectionDto>.EQ(election => election.Id, electionId);
                                          return electionCollection.Find(query).FirstOrDefault();
                                      };

            //return all elections for a participant
            Get["/forparticipant/{participantid}"] = parameters =>
                             {
                                 var electionCollection = m_mongoDataBase.GetCollection<ElectionDto>("Elections");
                                 string participantId = parameters.participantid;
                                 var query = Query<ElectionDto>.EQ(election => election.ParticipantId, participantId);
                                 return electionCollection.Find(query).ToList();
                             };
        }
开发者ID:rmacdonaldsmith,项目名称:CQRS-MassTransit,代码行数:32,代码来源:ElectionsModule.cs

示例3: MongoGridFS

 /// <summary>
 /// Initializes a new instance of the MongoGridFS class.
 /// </summary>
 /// <param name="database">The database containing the GridFS collections.</param>
 /// <param name="settings">The GridFS settings.</param>
 public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)
 {
     _database = database;
     _settings = settings.FrozenCopy();
     _chunks = database.GetCollection(settings.ChunksCollectionName);
     _files = database.GetCollection(settings.FilesCollectionName);
 }
开发者ID:staywellandy,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoGridFS.cs

示例4: Start

        public bool Start()
        {
            try
            {
                // Boot up DB
                mongoProcess = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = Properties.Resources.mongodb_exe,
                        Arguments = "--journal --dbpath " + Properties.Resources.db_path,
                        UseShellExecute = false,
                        RedirectStandardOutput = false,
                        CreateNoWindow = true
                    }
                };
                mongoProcess.Start();
            }
            catch (Exception)
            {
                // Getting an Exception here commonly means mongod is already up and running
            }

            mongo = new MongoClient();  // connect to localhost
            db = mongo.GetServer().GetDatabase(Properties.Resources.db_name);

            drawings = db.GetCollection<Drawing.Drawing>("drawings");
            highscores = db.GetCollection<Highscores.Highscore>("highscores");
            items = db.GetCollection<BsonDocument>("items");
            return true;
        }
开发者ID:TheAaltoWindrawTeam,项目名称:AaltoWindraw,代码行数:31,代码来源:MongoDBManager.cs

示例5: MongoDbRepositoryLinq

 public MongoDbRepositoryLinq()
 {
     string connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
     MongoClient client = new MongoClient(connectionString);
     server = client.GetServer();
     database = server.GetDatabase(DatabaseName);
     notes = database.GetCollection<NoteWithCategories>(CollectionName);
     categories = database.GetCollection<Category>(CollectionNameCategories);
 }
开发者ID:JohannesHoppe,项目名称:WebNoteNoSQL,代码行数:9,代码来源:MongoDbRepositoryLinq.cs

示例6: WikiMongoRepository

        public WikiMongoRepository()
        {
            var mongoClient = new MongoClient("mongodb://wikiAdmin:asdFFF99##@localhost:23750/wiki");
            var mongoServer = mongoClient.GetServer();
            db = mongoServer.GetDatabase("wiki");

            pages = db.GetCollection<WikiPage>("pages");
            tags = db.GetCollection<WikiTag>("tags");
            users = db.GetCollection<WikiUser>("users");
        }
开发者ID:frankhale,项目名称:random,代码行数:10,代码来源:WikiMongoRepositoryExample.cs

示例7: DrugLord

        public DrugLord()
        {
            database = MongoDatabase.Create(ConfigurationManager.AppSettings["mongo"]);

            money = database.GetCollection("money");
            money.EnsureIndex(IndexKeys.Ascending("userToken", "secretCode"), IndexOptions.SetUnique(true));

            drugs = database.GetCollection("drugs");
            drugs.EnsureIndex(IndexKeys.Ascending("userToken", "secretCode"), IndexOptions.SetUnique(true));
        }
开发者ID:STRUDSO,项目名称:RebusCodeCamp,代码行数:10,代码来源:DrugLord.svc.cs

示例8: FormMain

 public FormMain()
 {
     InitializeComponent();
     //var urlTo = MongoUrl.Create("mongodb://mongodb-endorphin.cloudapp.net:27017");
     var urlTo = MongoUrl.Create("mongodb://localhost:27017");
     var settingsTo = urlTo.ToServerSettings();
     _server = MongoServer.Create(settingsTo);
     _databaseCrawler = _server.GetDatabase("SyutkinCrawler");
     _pages = _databaseCrawler.GetCollection("Pages");
     _posts = _databaseCrawler.GetCollection("Posts");
 }
开发者ID:opcheese,项目名称:DlyaCrawlerov,代码行数:11,代码来源:FormMain.cs

示例9: BeforeEachTest

        public void BeforeEachTest()
        {
            var client = new MongoClient("mongodb://localhost:27017");
            Database = client.GetServer().GetDatabase("identity-testing");
            Users = Database.GetCollection<IdentityUser>("users");
            Roles = Database.GetCollection<IdentityRole>("roles");
            IdentityContext = new IdentityContext(Users, Roles);

            Database.DropCollection("users");
            Database.DropCollection("roles");
        }
开发者ID:Malkiat-Singh,项目名称:aspnet-identity-mongo,代码行数:11,代码来源:UserIntegrationTestsBase.cs

示例10: MongoGridFS

        /// <summary>
        /// Initializes a new instance of the MongoGridFS class.
        /// </summary>
        /// <param name="database">The database containing the GridFS collections.</param>
        /// <param name="settings">The GridFS settings.</param>
        public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)
        {
            settings = settings.Clone();
            settings.ApplyDefaultValues(database.Settings);
            settings.Freeze();

            _database = database;
            _settings = settings;
            _chunks = database.GetCollection(settings.Root + ".chunks");
            _files = database.GetCollection(settings.Root + ".files");
        }
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:16,代码来源:MongoGridFS.cs

示例11: PlaceService

 public PlaceService()
 {
     var connectionString = appSettings.Get ("MongoDB", "");
     client = new MongoClient (connectionString);
     server = client.GetServer ();
     db = server.GetDatabase ("geoapi");
     placescollection = db.GetCollection<PlaceResponse> ("place");
     triggerscollection = db.GetCollection<Trigger> ("trigger");
     if (!BsonClassMap.IsClassMapRegistered (typeof(PlaceResponse))) {
         BsonClassMap.RegisterClassMap<PlaceResponse> ();
     }
 }
开发者ID:voxon2,项目名称:SSGeoAPI,代码行数:12,代码来源:PlaceService.cs

示例12: MongoDBEventStore

        public MongoDBEventStore(string connectionString = DEFAULT_DATABASE_URI, IEventTypeResolver typeResolver = null, IEventConverter converter = null)
        {
            _database = MongoDatabase.Create(connectionString);
            _commits = _database.GetCollection<MongoCommit>("Commits");
            _events = _database.GetCollection<BsonDocument>("SourcedEvents");

            _converter = converter ?? new NullEventConverter();
            _formatter = new JsonEventFormatter(typeResolver ?? new SimpleEventTypeResolver());
            _translator = new StringEventTranslator();

            EnsureIndexes();
        }
开发者ID:otemnov,项目名称:ncqrs,代码行数:12,代码来源:MongoDBEventStore.cs

示例13: MongoDbPostRepository

        public MongoDbPostRepository(IMongoConnectionFactory connectionFactory)
        {
            db = connectionFactory.Create();

            db.GetCollection("posts").EnsureIndex(
                IndexKeys.Descending("Slug", "Version"),
                IndexOptions.SetUnique(true));

            db.GetCollection("sequences").EnsureIndex(
                IndexKeys.Descending("Name"),
                IndexOptions.SetUnique(true));
        }
开发者ID:richhildebrand,项目名称:BasicMVC4,代码行数:12,代码来源:MongoDbPostRepository.cs

示例14: StartPlace

        /// <summary>
        /// 清理用户名
        /// </summary>
        /// <param name="note"></param>
        public void StartPlace()
        {
            string connectionString = ConfigLoader.Config.DbPlayer;
            database = MongoDatabase.Create(connectionString);

            MongoCollection player = database.GetCollection("Player");
            int count = NewMethod(player, "UserID");
            Console.WriteLine("Player:" + count);

            MongoCollection user = database.GetCollection("UserLog");
            count = NewMethod2(user);
            Console.WriteLine("UserLog" + count);
        }
开发者ID:abel,项目名称:sinan,代码行数:17,代码来源:MinUserID.cs

示例15: Repository

        public Repository(string connection)
        {
            if (string.IsNullOrWhiteSpace(connection))
            {
                connection = "mongodb://notb544:27017";
            }

            _client = new MongoClient(connection);
            _server = _client.GetServer();
            _database = _server.GetDatabase("local", WriteConcern.Unacknowledged);
            _corporation = _database.GetCollection<Corporation>("Corporations");
            _realEstate = _database.GetCollection<RealEstate>("RealEstates");
        }
开发者ID:Koaleo,项目名称:IntegrationSpike,代码行数:13,代码来源:Repository.cs


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