95 lines
3.7 KiB
C#
95 lines
3.7 KiB
C#
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 JiShe.CollectBus.IotSystems.MessageIssueds;
|
|
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>();
|
|
|
|
public IMongoCollection<MessageIssued> MessageIssueds => Collection<MessageIssued>();
|
|
|
|
|
|
|
|
protected override void CreateModel(IMongoModelBuilder modelBuilder)
|
|
{
|
|
//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 }
|
|
// )
|
|
// );
|
|
// }
|
|
// );
|
|
|
|
// //// 创建索引
|
|
// //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
|
|
// // // }
|
|
// // // ));
|
|
|
|
|
|
// // //var indexKeys = Builders<BsonDocument>.IndexKeys
|
|
// // //.Ascending("CreationTime")
|
|
// // //.Ascending("OrderNumber");
|
|
|
|
// // //var indexOptions = new CreateIndexOptions
|
|
// // //{
|
|
// // // Background = true,
|
|
// // // Name = "IX_CreationTime_OrderNumber"
|
|
// // //};
|
|
// // //index.CreateOne(
|
|
// // //new CreateIndexModel<BsonDocument>(indexKeys, indexOptions));
|
|
|
|
// // //index.CreateOne(new CreateIndexModel<BsonDocument>(
|
|
// // // Builders<BsonDocument>.IndexKeys.Ascending(nameof(MeterReadingRecords)),
|
|
// // // new CreateIndexOptions
|
|
// // // {
|
|
// // // Unique = true
|
|
// // // }
|
|
// // // ));
|
|
// //});
|
|
|
|
//});
|
|
|
|
base.CreateModel(modelBuilder);
|
|
modelBuilder.ConfigureCollectBus();
|
|
}
|
|
}
|