fix(populate): 跳过空串关联 id,避免可选 Relation 存 "" 时 $in 转 ObjectId 抛 CastError 整页 500
bump 0.7.11
This commit is contained in:
@@ -79,9 +79,10 @@ export class MongoShrimpCrud<T> implements ShrimpCrud<T> {
|
||||
const allRefIds = new Set<string>()
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user