using Business.Core.Attributes; using Microsoft.Extensions.Options; using MongoDB.Bson; using MongoDB.Driver; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Business.Core.MongoDBHelper { /// /// MongoDB实现 /// public class MongoDBTools : IMongoDB where T : class { public readonly IMongoCollection mongoCollection; public IOptionsSnapshot _config; /// /// MongoDB帮助类 /// /// /// public MongoDBTools(IOptionsSnapshot config) { _config = config; //数据库链接 MongoClient client = new MongoClient(config.Value.connectstring); CollectionNameAttribute collectonName = typeof(T).GetCustomAttributes(typeof(CollectionNameAttribute), true).FirstOrDefault() as CollectionNameAttribute; if (collectonName == null) { throw new NotImplementedException("请配置Attribute属性!"); } //数据库 var database = client.GetDatabase(collectonName.DatabaseName); //表名 mongoCollection = database.GetCollection(collectonName.CollectionName); } public Task BulkInsert(List documents) { throw new NotImplementedException(); } public Task> GetAll() { throw new NotImplementedException(); } public Task GetOneByID(long id) { throw new NotImplementedException(); } public Task Inc(long id) { throw new NotImplementedException(); } public Task InsertMany(List documents) { throw new NotImplementedException(); } public Task InsertOne(T document) { return mongoCollection.InsertOneAsync(document); } public Task UpdateMultiFields(T document, long id) { throw new NotImplementedException(); } public Task UpdateOne(string name, long id) { throw new NotImplementedException(); } } }