mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Update mongodb
This commit is contained in:
@@ -20,7 +20,7 @@ namespace MongoDbTest
|
||||
new OrderInfo() { CreateTime = DateTime.Now, Name = "a2", Price = 3 }})
|
||||
.ExecuteReturnPkList<string>();
|
||||
|
||||
db.Deleteable(new OrderInfo() { Id="a" })
|
||||
var delrow=db.Deleteable(new OrderInfo() { Id= ids.Last() })
|
||||
.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
@@ -12,8 +12,14 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
public override List<Type> ExecuteReturnPkList<Type>()
|
||||
{
|
||||
base.ExecuteCommand();
|
||||
return ((MongoDbConnection)this.Ado.Connection).ObjectIds.Select(it=>(Type)(object)it).ToList();
|
||||
}
|
||||
public new async Task<List<Type>> ExecuteReturnPkListAsync<Type>()
|
||||
{
|
||||
await base.ExecuteCommandAsync();
|
||||
return ((MongoDbConnection)this.Ado.Connection).ObjectIds.Select(it => (Type)(object)it).ToList();
|
||||
}
|
||||
public override int ExecuteReturnIdentity()
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
|
@@ -39,8 +39,7 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings == null) return true;
|
||||
return this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public override string GetTranslationColumnName(string propertyName)
|
||||
@@ -99,7 +98,7 @@ namespace SqlSugar.MongoDb
|
||||
}
|
||||
else
|
||||
{
|
||||
return SqlTranslationLeft + name.ToLower(isAutoToLower).TrimEnd('"').TrimStart('"') + SqlTranslationRight;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
public override string GetUnionFomatSql(string sql)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using MongoDB.Bson;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
@@ -9,7 +10,7 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
public override string ToSqlString()
|
||||
{
|
||||
var sb = new StringBuilder("deleteMany b ");
|
||||
var sb = new StringBuilder($"deleteMany {this.GetTableNameString} ");
|
||||
var jsonObjects = new List<string>();
|
||||
foreach (var item in this.WhereInfos)
|
||||
{
|
||||
@@ -22,11 +23,24 @@ namespace SqlSugar.MongoDb
|
||||
sql = sql.Replace(startWithValue, "").Replace("'", "");
|
||||
var dict = new Dictionary<string, object>();
|
||||
var array = sql.Split(",");
|
||||
dict["_id"] = new Dictionary<string, object> { { "$in", array } }; // Fixed syntax for dictionary initialization
|
||||
string json = JsonSerializer.Serialize(dict, new JsonSerializerOptions
|
||||
var idStrings = sql.Split(",");
|
||||
|
||||
// 将字符串数组转为 ObjectId 列表(如果不是 ObjectId 可保留为字符串)
|
||||
var bsonArray = new BsonArray();
|
||||
foreach (var idStr in idStrings)
|
||||
{
|
||||
WriteIndented = false
|
||||
});
|
||||
bsonArray.Add(ObjectId.Parse(idStr)); // fallback 为普通字符串
|
||||
}
|
||||
|
||||
var filter = new BsonDocument
|
||||
{
|
||||
{ "_id", new BsonDocument { { "$in", bsonArray } } }
|
||||
};
|
||||
|
||||
string json = filter.ToJson(new MongoDB.Bson.IO.JsonWriterSettings
|
||||
{
|
||||
OutputMode = MongoDB.Bson.IO.JsonOutputMode.Shell
|
||||
}); // 使用 MongoDB 驱动的序列化
|
||||
jsonObjects.Add(json);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user