76 lines
3.0 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;
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-03-20 16:40:27 +08:00
2024-12-19 16:07:07 +08:00
protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
2025-03-20 16:40:27 +08:00
base.CreateModel(modelBuilder);
modelBuilder.ConfigureCollectBus();
2024-12-19 16:07:07 +08:00
2025-03-21 11:48:31 +08:00
//modelBuilder.Entity<MeterReadingRecords>(builder =>
//{
// // 创建索引
// builder.ConfigureIndexes(index =>
// {
// //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 11:48:31 +08:00
// //var indexKeys = Builders<BsonDocument>.IndexKeys
// //.Ascending("CreationTime")
// //.Ascending("OrderNumber");
2025-03-20 16:40:27 +08:00
2025-03-21 11:48:31 +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 11:48:31 +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 11:48:31 +08:00
//});
2025-03-20 16:40:27 +08:00
}
2024-12-19 16:07:07 +08:00
}