From 31b723839ed54de35ea528ad85d0df8b2c7850cf Mon Sep 17 00:00:00 2001 From: wc24 Date: Wed, 29 Jul 2026 14:56:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(populate):=20=E8=B7=B3=E8=BF=87=E7=A9=BA?= =?UTF-8?q?=E4=B8=B2=E5=85=B3=E8=81=94=20id=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E5=8F=AF=E9=80=89=20Relation=20=E5=AD=98=20""=20=E6=97=B6=20$i?= =?UTF-8?q?n=20=E8=BD=AC=20ObjectId=20=E6=8A=9B=20CastError=20=E6=95=B4?= =?UTF-8?q?=E9=A1=B5=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bump 0.7.11 --- package.json | 2 +- src/forMongo/MongoShrimpCrud.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 60db77d..74f8286 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shrimp-server", - "version": "0.7.10", + "version": "0.7.11", "description": "Shrimp 框架后端 — 声明式字段驱动的 Node.js 管理后台框架(Express + Mongoose + JWT)", "main": "dist/main/index.js", "types": "dist/main/index.d.ts", diff --git a/src/forMongo/MongoShrimpCrud.ts b/src/forMongo/MongoShrimpCrud.ts index cc7ff29..b69d044 100644 --- a/src/forMongo/MongoShrimpCrud.ts +++ b/src/forMongo/MongoShrimpCrud.ts @@ -79,9 +79,10 @@ export class MongoShrimpCrud implements ShrimpCrud { const allRefIds = new Set() for (const item of items) { const val = (item as any)[pop.key] + // 跳过空串:可选 Relation 常存 "",混进 { _id: { $in } } 会让 Mongoose 转 ObjectId 抛 CastError、整页 500。 if (Array.isArray(val)) { - val.forEach((id: any) => { if (id != null) allRefIds.add(String(id)) }) - } else if (val != null) { + val.forEach((id: any) => { if (id != null && id !== "") allRefIds.add(String(id)) }) + } else if (val != null && val !== "") { allRefIds.add(String(val)) } }