|
|
@@ -7,19 +7,20 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using Volo.Abp.Domain.Entities;
|
|
|
|
|
|
namespace Business.Core.MongoDBHelper
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// MongoDB实现
|
|
|
+ /// MongoDB帮助类
|
|
|
/// </summary>
|
|
|
- public class MongoDBTools<T> : IMongoDB<T> where T : class
|
|
|
+ public class MongoDBTools<T> : IMongoDB<T> where T : Entity<long>
|
|
|
{
|
|
|
public readonly IMongoCollection<T> mongoCollection;
|
|
|
public IOptionsSnapshot<Config> _config;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// MongoDB帮助类
|
|
|
+ /// MongoDB链接
|
|
|
/// </summary>
|
|
|
/// <param name="config"></param>
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
@@ -40,44 +41,58 @@ namespace Business.Core.MongoDBHelper
|
|
|
mongoCollection = database.GetCollection<T>(collectonName.CollectionName);
|
|
|
}
|
|
|
|
|
|
- public Task<long> BulkInsert(List<T> documents)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
-
|
|
|
- public Task<List<T>> GetAll()
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
-
|
|
|
- public Task<T> GetOneByID(long id)
|
|
|
+ /// <summary>
|
|
|
+ /// 插入一条数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="document"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public void InsertOne(T document)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ mongoCollection.InsertOne(document);
|
|
|
}
|
|
|
|
|
|
- public Task Inc(long id)
|
|
|
+ /// <summary>
|
|
|
+ /// 插入多条数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="documents"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public void InsertMany(List<T> documents)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ mongoCollection.InsertMany(documents,new InsertManyOptions() { IsOrdered = false});
|
|
|
}
|
|
|
|
|
|
- public Task InsertMany(List<T> documents)
|
|
|
+ /// <summary>
|
|
|
+ /// 更新一条数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="documents"></param>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public ReplaceOneResult UpdateOne(T documents,long id)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ return mongoCollection.ReplaceOne(Builders<T>.Filter.Eq(p=>p.Id, id), documents);
|
|
|
}
|
|
|
|
|
|
- public Task InsertOne(T document)
|
|
|
+ /// <summary>
|
|
|
+ /// 获取所有数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public List<T> GetAll()
|
|
|
{
|
|
|
- return mongoCollection.InsertOneAsync(document);
|
|
|
+ return mongoCollection.AsQueryable().ToList();
|
|
|
}
|
|
|
|
|
|
- public Task<UpdateResult> UpdateMultiFields(T document, long id)
|
|
|
+ /// <summary>
|
|
|
+ /// 跟据Id获取数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public T GetOneByID(long id)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ return mongoCollection.Find(p => p.Id == id).FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
- public Task<UpdateResult> UpdateOne(string name, long id)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
}
|
|
|
}
|