Update mongodb

This commit is contained in:
sunkaixuan 2025-06-23 19:41:06 +08:00
parent b39ef3f30e
commit 446af2afad
2 changed files with 15 additions and 2 deletions

View File

@ -21,6 +21,11 @@ namespace MongoDbTest
var data2 = db.Queryable<Student>().Where(it => it.Book.Price == 1).ToList();
if (data2.Count != 1) Cases.ThrowUnitError();
if (data2.First().Book.Price != 1) Cases.ThrowUnitError();
data2.First().Book.Price = 100;
db.Updateable(data2).ExecuteCommand();
var data3 = db.Queryable<Student>().Where(it => it.Book.Price == 100).ToList();
if (data3.Count != 1) Cases.ThrowUnitError();
if (data2.First().Book.Price != 100) Cases.ThrowUnitError();
}
[SqlSugar.SugarTable("UnitStudentdfsds3zzz1")]

View File

@ -121,8 +121,16 @@ namespace SqlSugar.MongoDb
}
else
{
var bsonValue = UtilMethods.MyCreate(col.Value);
setDoc[col.DbColumnName] = bsonValue;
if (col.IsJson)
{
var bsonValue = BsonDocument.Parse(col.Value?.ToString());
setDoc[col.DbColumnName] = bsonValue;
}
else
{
var bsonValue = UtilMethods.MyCreate(col.Value);
setDoc[col.DbColumnName] = bsonValue;
}
}
}