using JiShe.CollectBus.IotSystems.Devices; using JiShe.CollectBus.IotSystems.MessageReceiveds; using JiShe.CollectBus.IotSystems.MeterReadingRecords; using JiShe.CollectBus.IotSystems.Protocols; using JiShe.CollectBus.ShardingStrategy; using MongoDB.Bson; using MongoDB.Bson.Serialization; using MongoDB.Driver; using System; using System.Collections.Concurrent; using System.Collections.Generic; using Volo.Abp.Data; using Volo.Abp.MongoDB; using Volo.Abp.MultiTenancy; namespace JiShe.CollectBus.MongoDB; [IgnoreMultiTenancy] [ConnectionStringName(CollectBusDbProperties.MongoDbConnectionStringName)] public class CollectBusMongoDbContext : AbpMongoDbContext, ICollectBusMongoDbContext { /* Add mongo collections here. Example: * public IMongoCollection Questions => Collection(); */ public IMongoCollection MessageReceiveds => Collection(); public IMongoCollection MessageReceivedLogins => Collection(); public IMongoCollection MessageReceivedHeartbeats => Collection(); public IMongoCollection Devices => Collection(); public IMongoCollection ProtocolInfos => Collection(); protected override void CreateModel(IMongoModelBuilder modelBuilder) { modelBuilder.Entity(builder => { builder.CreateCollectionOptions.Collation = new Collation(locale: "en_US", strength: CollationStrength.Secondary); builder.ConfigureIndexes(indexes => { indexes.CreateOne( new CreateIndexModel( Builders.IndexKeys.Ascending("MyProperty"), new CreateIndexOptions { Unique = true } ) ); } ); //// 创建索引 //builder.ConfigureIndexes(index => //{ // //List> createIndexModels = new List>(); // //createIndexModels.Add(new CreateIndexModel( // // Builders.IndexKeys.Ascending(nameof(MeterReadingRecords)), // // new CreateIndexOptions // // { // // Unique = true // // } // // )); // //var indexKeys = Builders.IndexKeys // //.Ascending("CreationTime") // //.Ascending("OrderNumber"); // //var indexOptions = new CreateIndexOptions // //{ // // Background = true, // // Name = "IX_CreationTime_OrderNumber" // //}; // //index.CreateOne( // //new CreateIndexModel(indexKeys, indexOptions)); // //index.CreateOne(new CreateIndexModel( // // Builders.IndexKeys.Ascending(nameof(MeterReadingRecords)), // // new CreateIndexOptions // // { // // Unique = true // // } // // )); //}); }); base.CreateModel(modelBuilder); modelBuilder.ConfigureCollectBus(); } }