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


C# MongoCollection.CreateIndex方法代码示例

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


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

示例1: CommandEnvelopeRouteOnRequestCostcentreRepository

        public CommandEnvelopeRouteOnRequestCostcentreRepository(string connectionString)
            : base(connectionString)
        {
            _commandEnvelopeRouteOnRequestCostcentreCollection = CurrentMongoDB.GetCollection<CommandEnvelopeRouteOnRequestCostcentre>(_commandEnvelopeRouteOnRequestCostcentreCollectionName);
            _commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
            _commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.EnvelopeId));
            _commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.CostCentreId));
            _commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.EnvelopeRoutePriority));
            _commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.EnvelopeArrivalAtServerTick));
            _commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.DocumentType));

            _commandEnvelopeRoutingStatusCollection = CurrentMongoDB.GetCollection<CommandEnvelopeRoutingStatus>(_commandEnvelopeRoutingStatusCollectionName);
            _commandEnvelopeRoutingStatusCollection.EnsureIndex(IndexKeys<CommandEnvelopeRoutingStatus>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
            _commandEnvelopeRoutingStatusCollection.EnsureIndex(IndexKeys<CommandEnvelopeRoutingStatus>.Ascending(n => n.DestinationCostCentreApplicationId));
            _commandEnvelopeRoutingStatusCollection.EnsureIndex(IndexKeys<CommandEnvelopeRoutingStatus>.Ascending(n => n.EnvelopeDeliveredAtServerTick));

            _commandEnvelopeProcessingAuditCollection = CurrentMongoDB.GetCollection<CommandEnvelopeProcessingAudit>(_commandEnvelopeProcessingAuditCollectionName);
            _commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
            _commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.GeneratedByCostCentreApplicationId));
            _commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.RecipientCostCentreId));
            _commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.DocumentId));
            _commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.Status));
            _commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.ParentDocumentId));
            _commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.DateInserted));

            _CommandEnvelopeRoutingTrackerCollection = CurrentMongoDB.GetCollection<CommandEnvelopeRoutingTracker>(_commandEnvelopeRoutingTrackerCollectionName);

            _CommandEnvelopeRoutingTrackerCollection.CreateIndex(IndexKeys<CommandEnvelopeRoutingTracker>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
            _CommandEnvelopeRoutingTrackerCollection.CreateIndex(IndexKeys<CommandEnvelopeRoutingTracker>.Ascending(n => n.EnvelopeArrivalAtServerTick));
            _CommandEnvelopeRoutingTrackerCollection.CreateIndex(IndexKeys<CommandEnvelopeRoutingTracker>.Ascending(n => n.EnvelopeId));
        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:31,代码来源:CommandEnvelopeRouteOnRequestCostcentreRepository.cs

示例2: MongoDbEventStore

        public MongoDbEventStore(MongoDatabase database, string eventCollectionName, bool automaticallyCreateIndexes = true)
        {
            _eventBatches = database.GetCollection<MongoEventBatch>(eventCollectionName);

            if (automaticallyCreateIndexes)
            {
                _eventBatches.CreateIndex(IndexKeys.Ascending(GlobalSeqNoDocPath), IndexOptions.SetUnique(true).SetName(GlobalSeqUniquenessIndexName));
                _eventBatches.CreateIndex(IndexKeys.Ascending(AggregateRootIdDocPath, SeqNoDocPath), IndexOptions.SetUnique(true).SetName(SeqUniquenessIndexName));
            }
        }
开发者ID:linearregression,项目名称:Cirqus,代码行数:10,代码来源:MongoDbEventStore.cs

示例3: MongoDbRepository

        public MongoDbRepository(string connectionstring)
        {
            Trace.TraceInformation("MongoDbRepository.ctor, connectionstring: {0}", connectionstring);

            _mdbClient = new MongoClient(connectionstring);
            _mdbServer = _mdbClient.GetServer();
            _mdb = _mdbServer.GetDatabase(DBNAME);

            _mdbCol = _mdb.GetCollection("Trainings");
            _mdbCol.CreateIndex(new IndexKeysBuilder().Ascending("Matchcode"), IndexOptions.SetUnique(true));
            _mdbCol.CreateIndex(new IndexKeysBuilder().Ascending("TrainerMatchcode"));
        }
开发者ID:ralfw,项目名称:instavote.open,代码行数:12,代码来源:MongoDbRepository.cs

示例4: Setup

        public void Setup()
        {
            _collection = LegacyTestConfiguration.GetCollection<B>();

            _collection.Drop();
            _collection.CreateIndex(new IndexKeysBuilder().Ascending("a", "b"), IndexOptions.SetName("i"));
            _collection.CreateIndex(new IndexKeysBuilder().Ascending("a", "b"), IndexOptions.SetName("i"));

            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 1, b = 10, c = 100 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 2, b = 20, c = 200 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 3, b = 30, c = 300 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 4, b = 40, c = 400 });
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:13,代码来源:WithIndexTests.cs

示例5: MongoDbPessimisticLocker

        internal MongoDbPessimisticLocker(MongoDatabase database, int ttl, bool dropCollection)
        {
            locks = database.GetCollection<PessimisticLockDto>("PessimisticLocks");
            if (dropCollection)
                locks.Drop();

            var indexes = locks.GetIndexes().ToArray();
            var tsIndex = indexes.FirstOrDefault(x => x.Name != "ts");
            if (tsIndex == null)
            {
                locks.CreateIndex(new IndexKeysBuilder().Ascending("ts"),
                    new IndexOptionsBuilder().SetTimeToLive(TimeSpan.FromSeconds(ttl)).SetName("ts"));
            }
            locks.CreateIndex(new IndexKeysBuilder().Ascending("kid"), new IndexOptionsBuilder().SetUnique(false));
        }
开发者ID:vedmiediev,项目名称:SimpleLeaderElection,代码行数:15,代码来源:MongoDbPessimisticLocker.cs

示例6: InitMongoDb

 private void InitMongoDb()
 {
     _client = new MongoClient("mongodb://localhost");
     _server = _client.GetServer();
     _db = _server.GetDatabase("RTrack");
     _userCollection = _db.GetCollection<User>(typeof(User).Name);
     _userCollection.CreateIndex(IndexKeys<User>.Ascending(u => u.UserName), IndexOptions.SetUnique(true));
 }
开发者ID:carlosjorgepedro,项目名称:RTrack,代码行数:8,代码来源:AuthRepository.cs

示例7: Open

        // 初始化
        // parameters:
        public int Open(
            // string strMongoDbConnStr,
            MongoClient client,
            string strInstancePrefix,
            out string strError)
        {
            strError = "";

#if NO
            if (string.IsNullOrEmpty(strMongoDbConnStr) == true)
            {
                strError = "strMongoDbConnStr 参数值不应为空";
                return -1;
            }
#endif

            if (string.IsNullOrEmpty(strInstancePrefix) == false)
                strInstancePrefix = strInstancePrefix + "_";

            _logDatabaseName = strInstancePrefix + "accessLog";

#if NO
            try
            {
                this._mongoClient = new MongoClient(strMongoDbConnStr);
            }
            catch (Exception ex)
            {
                strError = "初始化 MongoClient 时出错: " + ex.Message;
                return -1;
            }
#endif

            var server = client.GetServer();

            {
                var db = server.GetDatabase(this._logDatabaseName);

                _logCollection = db.GetCollection<AccessLogItem>("accessLog");
                // _logCollection.DropAllIndexes();
                if (_logCollection.GetIndexes().Count == 0)
                {
#if NO
                    _logCollection.CreateIndex(new IndexKeysBuilder().Ascending("OperTime"),
                        IndexOptions.SetUnique(false));
#endif
                    CreateIndex();
                }
            }

            _itemCount = new DailyItemCount();
            string date = GetToday();
            _itemCount.SetValue(date, GetItemCount(date));
            return 0;
        }
开发者ID:renyh1013,项目名称:dp2,代码行数:57,代码来源:AccessLogDatabase.cs

示例8: Setup

        public void Setup()
        {
            _collection = LegacyTestConfiguration.GetCollection<B>();

            _collection.Drop();
            _collection.CreateIndex("Value", "SubValues.Value");

            //numeric
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), Value = (byte)1, SubValues = new List<C>() { new C(2f), new C(3), new C(4D), new C(5UL) } });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), Value = 2f, SubValues = new List<C>() { new C(6f), new C(7), new C(8D), new C(9UL) } });
            //strings
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), Value = "1", SubValues = new List<C>() { new C("2"), new C("3"), new C("4"), new C("5") } });
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:13,代码来源:CSharp900Tests.cs

示例9: SetUp

        public void SetUp()
        {
            var db = Configuration.TestDatabase;
            _collection = db.GetCollection<GeoClass>("geo");

            _collection.Drop();
            _collection.CreateIndex(IndexKeys<GeoClass>.GeoSpatialSpherical(x => x.Location));
            _collection.CreateIndex(IndexKeys<GeoClass>.GeoSpatialSpherical(x => x.Surrounding));

            var doc = new GeoClass
            {
                Id = 1,
                Location = GeoJson.Point(GeoJson.Geographic(40.5, 18.5)),
                Surrounding = GeoJson.Polygon(
                    GeoJson.Geographic(40, 18),
                    GeoJson.Geographic(40, 19),
                    GeoJson.Geographic(41, 19),
                    GeoJson.Geographic(40, 18))
            };

            _collection.Save(doc);
        }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:22,代码来源:QueryBuilderGeoJsonIntegrationTests.cs

示例10: Repository

        public Repository()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString;
              MongoClient client = new MongoClient(connectionString);
              MongoServer server = client.GetServer();
              MongoDatabase database = server.GetDatabase(ConfigurationManager.AppSettings["Database"]);

              seedCollection = database.GetCollection<Seed>("seed");
              seedCollection.CreateIndex(IndexKeys<Seed>.Ascending(_ => _.ImageHash));

              memeCollection = database.GetCollection<Meme>("meme");

              userCollection = database.GetCollection<User>("user");

              userCommentCollection = database.GetCollection<UserComment>("userComment");

              try
              {
            if (!BsonClassMap.IsClassMapRegistered(typeof(List<IComment>)))
            {
              BsonClassMap.RegisterClassMap<List<IComment>>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(Comment)))
            {
              BsonClassMap.RegisterClassMap<Comment>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(PositionRef)))
            {
              BsonClassMap.RegisterClassMap<PositionRef>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(List<IReply>)))
            {
              BsonClassMap.RegisterClassMap<List<IReply>>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(Reply)))
            {
              BsonClassMap.RegisterClassMap<Reply>();
            }
              }
              catch (Exception)
              {

            throw;
              }
        }
开发者ID:szwork2013,项目名称:sb004,代码行数:45,代码来源:Repository.cs

示例11: Insert

        public static void Insert(MongoCollection<Currency> collection, Currency currency)
        {
            try
            {
                collection.CreateIndex(IndexKeys<Currency>.Descending(c => c.Date));

                var result =
                    (from c in collection.AsQueryable<Currency>()
                     where c.Date == currency.Date
                     select c)
                    .Count();

                if (result == 0)
                    collection.Insert(currency);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
开发者ID:jongh0,项目名称:MTree,代码行数:20,代码来源:Program.cs

示例12: Initialize

    public override void Initialize(string name, NameValueCollection config)
    {
      ApplicationName = config["applicationName"] ?? HostingEnvironment.ApplicationVirtualPath;

      var connString = config["connectionString"];
      var connStringName = config["connectionStringName"];
      if ((connString != null) && (connStringName != null))
      {
        throw new ConfigurationErrorsException("Both parmeters connectionString and connectionStringName can not be specified");
      }
      if (connString == null)
      {
        if (connStringName == null)
        {
          throw new ConfigurationErrorsException("Either connectionString or connectionStringName parameter must be specified");
        }
        var settings = ConfigurationManager.ConnectionStrings[connStringName];
        if (settings == null)
        {
          throw new ConfigurationErrorsException(string.Format("Connection string {0} not found", connStringName));
        }
        connString = settings.ConnectionString;
      }
      mongoCollection = new MongoClient(connString).GetServer().GetDatabase(config["database"] ?? "ASPNETDB").GetCollection(config["collection"] ?? "Profiles");
      mongoCollection.CreateIndex("ApplicationName");
      mongoCollection.CreateIndex("ApplicationName", "IsAnonymous");
      mongoCollection.CreateIndex("ApplicationName", "IsAnonymous", "LastActivityDate");
      mongoCollection.CreateIndex("ApplicationName", "IsAnonymous", "LastActivityDate", "Username");
      mongoCollection.CreateIndex("ApplicationName", "IsAnonymous", "Username");
      mongoCollection.CreateIndex("ApplicationName", "LastActivityDate");
      mongoCollection.CreateIndex("ApplicationName", "Username");
      mongoCollection.CreateIndex("ApplicationName", "Username", "IsAnonymous");

      base.Initialize(name, config);
    }
开发者ID:BraveNewMath,项目名称:MongoDB.Web,代码行数:35,代码来源:MongoDBProfileProvider.cs

示例13: Initialize

 public override void Initialize(string name, NameValueCollection config)
 {
     _mongoCollection = new MongoClient(config["connectionString"] ?? "mongodb://localhost").GetServer().GetDatabase(config["database"] ?? "ASPNETDB").GetCollection(config["collection"] ?? "OutputCache");
     _mongoCollection.CreateIndex("Key");
     base.Initialize(name, config);
 }
开发者ID:BraveNewMath,项目名称:MongoDB.Web,代码行数:6,代码来源:MongoDBOutputCacheProvider.cs

示例14: MongoDbTimeoutStorage

 /// <summary>
 /// Constructs the timeout storage, connecting to the Mongo database pointed to by the given connection string,
 /// storing the timeouts in the given collection
 /// </summary>
 public MongoDbTimeoutStorage(string connectionString, string collectionName)
 {
     var database = MongoHelper.GetDatabase(connectionString);
     collection = database.GetCollection(collectionName);
     collection.CreateIndex(IndexKeys.Ascending(TimeProperty), IndexOptions.SetBackground(true).SetUnique(false));
 }
开发者ID:CasperTDK,项目名称:RebusSnoopRefactor,代码行数:10,代码来源:MongoDbTimeoutStorage.cs

示例15: EnsureUniqueIndexOnRoleName

 public static void EnsureUniqueIndexOnRoleName(MongoCollection roles)
 {
     var roleName = new IndexKeysBuilder<IdentityRole>().Ascending(t => t.Name);
     var unique = new IndexOptionsBuilder().SetUnique(true);
     roles.CreateIndex(roleName, unique);
 }
开发者ID:Malkiat-Singh,项目名称:aspnet-identity-mongo,代码行数:6,代码来源:IndexChecks.cs


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