mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-24 16:43:17 +08:00
Update mongodb
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Bson.IO;
|
using MongoDB.Bson.IO;
|
||||||
using MongoDB.Bson.Serialization;
|
using MongoDB.Bson.Serialization;
|
||||||
|
using MongoDB.Driver;
|
||||||
using NetTaste;
|
using NetTaste;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
@@ -305,8 +306,13 @@ namespace SqlSugar.MongoDb
|
|||||||
foreach (var group in grouped)
|
foreach (var group in grouped)
|
||||||
{
|
{
|
||||||
BsonDocument doc = new BsonDocument();
|
BsonDocument doc = new BsonDocument();
|
||||||
|
var existsId = false;
|
||||||
foreach (var col in group)
|
foreach (var col in group)
|
||||||
{
|
{
|
||||||
|
if (col.DbColumnName == "_id")
|
||||||
|
{
|
||||||
|
existsId = true;
|
||||||
|
}
|
||||||
// 自动推断类型,如 string、int、bool、DateTime、ObjectId 等
|
// 自动推断类型,如 string、int、bool、DateTime、ObjectId 等
|
||||||
if (col.IsJson == true)
|
if (col.IsJson == true)
|
||||||
{
|
{
|
||||||
@@ -330,7 +336,10 @@ namespace SqlSugar.MongoDb
|
|||||||
doc[col.DbColumnName] = UtilMethods.MyCreate(col.Value);
|
doc[col.DbColumnName] = UtilMethods.MyCreate(col.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (existsId == false)
|
||||||
|
{
|
||||||
|
doc["_id"] = ObjectId.GenerateNewId();
|
||||||
|
}
|
||||||
// 转为 JSON 字符串(标准 MongoDB shell 格式)
|
// 转为 JSON 字符串(标准 MongoDB shell 格式)
|
||||||
string json = doc.ToJson(UtilMethods.GetJsonWriterSettings());
|
string json = doc.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user