From feb5d298e18476804deec8ae420773da1de26c52 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 27 Jun 2025 16:22:17 +0800 Subject: [PATCH] Update mongodb --- .../MongoDbTest/UnitTest/QueryLeftJoin.cs | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryLeftJoin.cs b/Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryLeftJoin.cs index cf6236739..9dea6f88c 100644 --- a/Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryLeftJoin.cs +++ b/Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryLeftJoin.cs @@ -31,12 +31,38 @@ namespace MongoDbTest db.Updateable(db.Queryable().First(it => it.SchoolId == ids.Last())).ExecuteCommand(); if (db.Queryable().First(it => it.SchoolId == ids.Last()).Name != "TestStudent") Cases.ThrowUnitError(); - //var list=db.Queryable() - // .LeftJoin((x, y) => x.SchoolId == y.Id) - // .Where((x,y)=>x.Name =="a"||y.Name=="a") - // .Select(x => new + var adoTest= db.Ado.GetDataTable(@"aggregate UnitStudent123131 [ + { + $lookup: { + from: ""UnitSchool123131"", + localField: ""SchoolId"", + foreignField: ""_id"", + as: ""y"" + } + }, + { + $unwind: { + path: ""$y"", + preserveNullAndEmptyArrays: true + } + }, + { + $project: { + _id: 0, + StudentName: ""$Name"", + SchoolName: { + $ifNull: [""$y.Name"", null] + } + } + } + ]"); + + //var list = db.Queryable() + // .LeftJoin((x, y) => x.SchoolId == y.Id) + // .Select((x,y) => new // { - // id=x.Name + // StudentName= x.Name, + // SchoolName= y.Name // }).ToList(); } [SqlSugar.SugarTable("UnitStudent123131")]