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


C# MongoCollection.EnsureIndex方法代码示例

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


在下文中一共展示了MongoCollection.EnsureIndex方法的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: MongoDbBlackBox

        public MongoDbBlackBox(string connectionstring, string eventstorename)
        {
            var mdbClient = new MongoClient(connectionstring);
            var mdbServer = mdbClient.GetServer();
            var mdb = mdbServer.GetDatabase(eventstorename);

            _eventCol = mdb.GetCollection("Events");
            _eventCol.EnsureIndex(new IndexKeysBuilder().Ascending("sequencenumber"));
            _eventCol.EnsureIndex(new IndexKeysBuilder().Ascending("name"));
            _eventCol.EnsureIndex(new IndexKeysBuilder().Ascending("context"));
        }
开发者ID:jbaehr,项目名称:NBlackBox,代码行数:11,代码来源:MongoDbBlackBox.cs

示例3: MongoDataProvider

        public MongoDataProvider(string connectionString)
            : base(connectionString)
        {
            var databaseName = MongoUrl.Create(connectionString).DatabaseName;
            var server = MongoServer.Create(connectionString);
            var database = server.GetDatabase(databaseName);

            _items = database.GetCollection<ItemDto>("items");
            _items.EnsureIndex(IndexKeys.Ascending(new[] {"ParentId"}));
            _items.EnsureIndex(IndexKeys.Ascending(new[] {"TemplateId"}));
        }
开发者ID:pbering,项目名称:SitecoreData,代码行数:11,代码来源:MongoDataProvider.cs

示例4: CommandRoutingOnRequestMongoRepository

        public CommandRoutingOnRequestMongoRepository(string connectionStringM1)
            : base(connectionStringM1)
        {
            _CommandRouteOnRequestCollection = CurrentMongoDB.GetCollection<CommandRouteOnRequest>(_commandRouteOnRequestCollectionName);
            _CommandRouteOnRequestCostcentreCollection = CurrentMongoDB.GetCollection<CommandRouteOnRequestCostcentre>(_commandRouteOnRequestCostcentreCollectionName);
            _commandRoutingStatusCollection = CurrentMongoDB.GetCollection<CommandRoutingStatus>(_commandCommandRoutingStatusCollectionName);
            _counterHelper = new IdCounterHelper(connectionStringM1);

            _CommandRouteOnRequestCollection.EnsureIndex(IndexKeys<CommandRouteOnRequest>.Ascending(n => n.CommandId), IndexOptions.SetUnique(true));
            _CommandRouteOnRequestCollection.EnsureIndex(IndexKeys<CommandRouteOnRequest>.Ascending(n => n.DocumentId));
            _CommandRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandRouteOnRequestCostcentre>.Ascending(n => n.CommandRouteOnRequestId).Ascending(n => n.CostCentreId), IndexOptions.SetUnique(true));
            _commandRoutingStatusCollection.EnsureIndex(IndexKeys<CommandRoutingStatus>.Ascending(n => n.CommandRouteOnRequestId).Ascending(n => n.DestinationCostCentreApplicationId), IndexOptions.SetUnique(true));
            _commandRoutingStatusCollection.EnsureIndex(IndexKeys<CommandRoutingStatus>.Ascending(n => n.CommandId).Ascending(n => n.DestinationCostCentreApplicationId), IndexOptions.SetUnique(true));
        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:14,代码来源:Repository.cs

示例5: Setup

        public void Setup()
        {
            _server = Configuration.TestServer;
            _database = Configuration.TestDatabase;
            _collection = Configuration.GetTestCollection<B>();

            _collection.Drop();
            _collection.EnsureIndex(new IndexKeysBuilder().Ascending("a", "b"), IndexOptions.SetName("i"));
            _collection.EnsureIndex(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:einaregilsson,项目名称:mongo-csharp-driver,代码行数:15,代码来源:WithIndexTests.cs

示例6: TestSetUp

 public void TestSetUp()
 {
     if (_testDb.CollectionExists(TestCollectionName))
         _testDb.DropCollection(TestCollectionName);
     _collection = _testDb.GetCollection<BsonDocument>(TestCollectionName);
     _collection.EnsureIndex(IndexKeys.Ascending("key"), IndexOptions.SetUnique(true));
 }
开发者ID:KlaudWerk,项目名称:WSHumanTask,代码行数:7,代码来源:MongoPropertySchemaSetTest.cs

示例7: Create

        public void Create(MongoCollection collection,bool isBackground)
        {
            var index  = OnBuildIndex();
          
            log.Debug("Index {0}: {1}",name,index);
            log.Info("Ensuring index {0} exists on collection {1}",name,collection.Name);

            collection.EnsureIndex(index, new IndexOptionsBuilder().SetBackground(isBackground).SetName(name));
        }
开发者ID:BernhardGlueck,项目名称:Phare,代码行数:9,代码来源:IndexDefinition.cs

示例8: 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

示例9: PatientRepository

        public PatientRepository()
        {
            _server = new MongoServer(new MongoServerSettings { Server = new MongoServerAddress(_DBHOST), SafeMode = SafeMode.True });

            //patients
            _patients = _server.GetDatabase(_DBNAME).GetCollection<PatientModel>("patients");
            _patients.EnsureIndex(IndexKeys.Ascending("_id"), IndexOptions.SetUnique(true));
            _gridFS = _server.GetDatabase(_DBNAME).GridFS;

            new MongoDB.Web.Providers.MongoDBMembershipProvider();
        }
开发者ID:snasser,项目名称:patient_portal,代码行数:11,代码来源:PatientRepository.cs

示例10: SetUp

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

            _collection.Drop();
            _collection.EnsureIndex(IndexKeys<GeoClass>.GeoSpatialSpherical(x => x.Location));
            _collection.EnsureIndex(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:einaregilsson,项目名称:mongo-csharp-driver,代码行数:22,代码来源:QueryBuilderGeoJsonIntegrationTests.cs

示例11: CommandProcessingAuditRepository

 public CommandProcessingAuditRepository(string connectionString) : base(connectionString)
 {
   _commandProcessingAuditCollection = CurrentMongoDB.GetCollection<CommandProcessingAudit>(_commandProcessingAuditCollectionName);
   _commandProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
   _commandProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.CostCentreApplicationId));
   _commandProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.Status));
   _commandProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.DocumentId));
   _commandProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.ParentDocumentId));
   _commandProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.DateInserted));
 }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:10,代码来源:CommandProcessingAuditRepository.cs

示例12: GuardarProveedor

 public Boolean GuardarProveedor(Proveedor P)
 {
     try
     {
         coleccion = bd.GetCollection<Proveedor>("Proveedor");
         coleccion.EnsureIndex(new IndexKeysBuilder().
             Ascending("Rut"), IndexOptions.SetUnique(true));
         this.mensaje.Append(coleccion.Insert(P).Response.ToString());
         return true;
     }
     catch (MongoSafeModeException MSME)
     {
         this.mensaje.Append("Rut Duplicado: " + P.Rut);
     }
     catch (Exception E)
     {
         this.mensaje.Append(E.Message);
     }
     return false;
 }
开发者ID:PuertoSolutions,项目名称:InventarioProclean,代码行数:20,代码来源:MongoHandler.cs

示例13: EnsureSession

        public MessageSessionInfo EnsureSession(string appName, string sessionId, ObjectId from, ObjectId to, MongoCollection<MessageSessionInfo> collection)
        {
            var session = collection.Find(Query.EQ("session_id", sessionId)).SetFields("session_id", "user_1", "user_2", "user1_is_deleted", "user2_is_deleted").FirstOrDefault();

            if (session == null)
            {
                session = new MessageSessionInfo()
                {
                    SessionId = sessionId,
                    User1 = from,
                    User2 = to,
                    Messages = new MessageInfo[0],
                    LastUpdated = DateTime.Now,
                    UnreadMessagesUser1 = 0,
                    UnreadMessagesUser2 = 0
                };
                collection.EnsureIndex("session_id");
                collection.Insert(session);
            }
            return session;
        }
开发者ID:xoperator,项目名称:GoKapara,代码行数:21,代码来源:UserMessagesDataProvider.cs

示例14: GroupByCount

        /// <summary>
        /// Calculate the amount of documents
        /// </summary>
        /// <param name="name">Field name to group by</param>
        /// <returns>Document list represented by "Key" and "Value" inside aggregate result object</returns>
        public AggregateResult GroupByCount(string name, MongoCollection collection, BsonDocument sort, BsonDocument limit, BsonDocument skip, BsonDocument match, bool countGroups =false)
        {
            // prepare pipeline operations
            var group = new BsonDocument
            {
                {
                    "$group",
                    new BsonDocument
                    {
                        {
                            "_id", new BsonDocument
                            {
                                {
                                    "Key","$" + name
                                }
                            }
                        },
                        {
                            "Value", new BsonDocument
                            {
                                {
                                    "$sum", 1
                                }
                            }
                        }
                    }
                }
            };

            var project = new BsonDocument
            {
                {
                    "$project",
                    new BsonDocument
                    {
                        {"_id", 0}, // remove reference to _id
                        {"Key","$_id.Key"}, // set reference to "_id.Name" as "UserName"
                        {"Value", 1}, // dont  change "Count"
                    }
                }
            };

            List<BsonDocument> pipeline = new List<BsonDocument>{ };
            if (match != null)
                pipeline.Add(match);

            pipeline.Add(group);
            if (countGroups)
            {
                var total = new BsonDocument
                {
                    {
                        "$group",
                        new BsonDocument
                        {
                            {
                                "_id", 0
                            },
                            {
                                "Total", new BsonDocument
                                {
                                    {
                                        "$sum", 1
                                    }
                                }
                            }
                        }
                    }
                };

                pipeline.Add(total);
            }
            else
            {
                pipeline.Add(project);

                if (sort != null)
                {
                    pipeline.Add(sort);
                }
                pipeline.Add(skip);
                pipeline.Add(limit);
            }
            collection.EnsureIndex(IndexKeys.Ascending(name));
            return collection.Aggregate(pipeline);
        }
开发者ID:xoperator,项目名称:GoKapara,代码行数:91,代码来源:ActivityDataProvider.cs

示例15: StudentManager

        static StudentManager()
        {
            collection = new MongoClient("mongodb://localhost").GetServer().GetDatabase("EAMSystem").GetCollection<Student>("Students");

            collection.EnsureIndex("StuNo");
        }
开发者ID:johnfelipe,项目名称:EducationAdminManagementSystem,代码行数:6,代码来源:Student.cs


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