95 lines
3.7 KiB
C#
Raw Normal View History

2025-03-14 14:28:04 +08:00
using JiShe.CollectBus.IotSystems.Devices;
using JiShe.CollectBus.IotSystems.MessageReceiveds;
2025-03-18 22:43:24 +08:00
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
2025-03-14 14:28:04 +08:00
using JiShe.CollectBus.IotSystems.Protocols;
2025-03-20 16:40:27 +08:00
using JiShe.CollectBus.ShardingStrategy;
2025-03-19 22:52:53 +08:00
using MongoDB.Bson;
2025-03-20 16:40:27 +08:00
using MongoDB.Bson.Serialization;
2024-12-19 16:07:07 +08:00
using MongoDB.Driver;
2025-03-19 22:52:53 +08:00
using System;
2025-03-20 16:40:27 +08:00
using System.Collections.Concurrent;
2025-03-19 22:52:53 +08:00
using System.Collections.Generic;
2025-04-16 16:12:38 +08:00
using JiShe.CollectBus.IotSystems.MessageIssueds;
2024-12-19 16:07:07 +08:00
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<Question> Questions => Collection<Question>();
*/
public IMongoCollection<MessageReceived> MessageReceiveds => Collection<MessageReceived>();
public IMongoCollection<MessageReceivedLogin> MessageReceivedLogins => Collection<MessageReceivedLogin>();
public IMongoCollection<MessageReceivedHeartbeat> MessageReceivedHeartbeats => Collection<MessageReceivedHeartbeat>();
public IMongoCollection<Device> Devices => Collection<Device>();
public IMongoCollection<ProtocolInfo> ProtocolInfos => Collection<ProtocolInfo>();
2025-04-16 16:12:38 +08:00
public IMongoCollection<MessageIssued> MessageIssueds => Collection<MessageIssued>();
2024-12-19 16:07:07 +08:00
protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
2025-03-21 15:07:38 +08:00
//modelBuilder.Entity<MeterReadingRecords>(builder =>
//{
// builder.CreateCollectionOptions.Collation = new Collation(locale: "en_US", strength: CollationStrength.Secondary);
// builder.ConfigureIndexes(indexes =>
// {
// indexes.CreateOne(
// new CreateIndexModel<BsonDocument>(
// Builders<BsonDocument>.IndexKeys.Ascending("MyProperty"),
// new CreateIndexOptions { Unique = true }
// )
// );
// }
// );
2025-03-21 14:29:05 +08:00
2025-03-21 15:07:38 +08:00
// //// 创建索引
// //builder.ConfigureIndexes(index =>
// //{
2025-03-21 14:29:05 +08:00
2024-12-19 16:07:07 +08:00
2025-03-21 15:07:38 +08:00
// // //List<CreateIndexModel<BsonDocument>> createIndexModels = new List<CreateIndexModel<BsonDocument>>();
// // //createIndexModels.Add(new CreateIndexModel<BsonDocument>(
// // // Builders<BsonDocument>.IndexKeys.Ascending(nameof(MeterReadingRecords)),
// // // new CreateIndexOptions
// // // {
// // // Unique = true
// // // }
// // // ));
2025-03-20 16:40:27 +08:00
2025-03-21 15:07:38 +08:00
// // //var indexKeys = Builders<BsonDocument>.IndexKeys
// // //.Ascending("CreationTime")
// // //.Ascending("OrderNumber");
2025-03-20 16:40:27 +08:00
2025-03-21 15:07:38 +08:00
// // //var indexOptions = new CreateIndexOptions
// // //{
// // // Background = true,
// // // Name = "IX_CreationTime_OrderNumber"
// // //};
// // //index.CreateOne(
// // //new CreateIndexModel<BsonDocument>(indexKeys, indexOptions));
2025-03-20 16:40:27 +08:00
2025-03-21 15:07:38 +08:00
// // //index.CreateOne(new CreateIndexModel<BsonDocument>(
// // // Builders<BsonDocument>.IndexKeys.Ascending(nameof(MeterReadingRecords)),
// // // new CreateIndexOptions
// // // {
// // // Unique = true
// // // }
// // // ));
// //});
2025-03-19 22:52:53 +08:00
2025-03-21 15:07:38 +08:00
//});
2025-03-21 14:29:05 +08:00
base.CreateModel(modelBuilder);
modelBuilder.ConfigureCollectBus();
2025-03-20 16:40:27 +08:00
}
2024-12-19 16:07:07 +08:00
}