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 }})
|
new OrderInfo() { CreateTime = DateTime.Now, Name = "a2", Price = 3 }})
|
||||||
.ExecuteReturnPkList<string>();
|
.ExecuteReturnPkList<string>();
|
||||||
|
|
||||||
db.Deleteable(new OrderInfo() { Id="a" })
|
var delrow=db.Deleteable(new OrderInfo() { Id= ids.Last() })
|
||||||
.ExecuteCommand();
|
.ExecuteCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,8 +12,14 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
public override List<Type> ExecuteReturnPkList<Type>()
|
public override List<Type> ExecuteReturnPkList<Type>()
|
||||||
{
|
{
|
||||||
|
base.ExecuteCommand();
|
||||||
return ((MongoDbConnection)this.Ado.Connection).ObjectIds.Select(it=>(Type)(object)it).ToList();
|
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()
|
public override int ExecuteReturnIdentity()
|
||||||
{
|
{
|
||||||
InsertBuilder.IsReturnIdentity = true;
|
InsertBuilder.IsReturnIdentity = true;
|
||||||
|
@@ -39,8 +39,7 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (this.Context.CurrentConnectionConfig.MoreSettings == null) return true;
|
return false;
|
||||||
return this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string GetTranslationColumnName(string propertyName)
|
public override string GetTranslationColumnName(string propertyName)
|
||||||
@@ -99,7 +98,7 @@ namespace SqlSugar.MongoDb
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return SqlTranslationLeft + name.ToLower(isAutoToLower).TrimEnd('"').TrimStart('"') + SqlTranslationRight;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string GetUnionFomatSql(string sql)
|
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.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@@ -9,7 +10,7 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
public override string ToSqlString()
|
public override string ToSqlString()
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder("deleteMany b ");
|
var sb = new StringBuilder($"deleteMany {this.GetTableNameString} ");
|
||||||
var jsonObjects = new List<string>();
|
var jsonObjects = new List<string>();
|
||||||
foreach (var item in this.WhereInfos)
|
foreach (var item in this.WhereInfos)
|
||||||
{
|
{
|
||||||
@@ -22,11 +23,24 @@ namespace SqlSugar.MongoDb
|
|||||||
sql = sql.Replace(startWithValue, "").Replace("'", "");
|
sql = sql.Replace(startWithValue, "").Replace("'", "");
|
||||||
var dict = new Dictionary<string, object>();
|
var dict = new Dictionary<string, object>();
|
||||||
var array = sql.Split(",");
|
var array = sql.Split(",");
|
||||||
dict["_id"] = new Dictionary<string, object> { { "$in", array } }; // Fixed syntax for dictionary initialization
|
var idStrings = sql.Split(",");
|
||||||
string json = JsonSerializer.Serialize(dict, new JsonSerializerOptions
|
|
||||||
|
// 将字符串数组转为 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);
|
jsonObjects.Add(json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user