我正在使用以下查询根据名为sortIndex的字段按升序填充MongoDB中的项目。有时虽然数据库中的项目没有sortIndex字段。通过以下查询,具有空sortIndex的项目显示在顶部,我想知道如何让它们显示在底部。我需要为此进行两次查询还是可以使用一次查询?.populate({path:'slides',options:{sort:{'sortIndex':'ascending'}}}) 最佳答案 你可以这样做:db.collection.aggregate([{$addFields:{hasValue:{$cond:[{$