猫鼬允许不存在的字段进行排序.如何仅限制现有字段?



下面的查询返回数据,但hgf字段在 document(db( 中不存在。如何限制仅对现有字段的排序?

files.find({ account_id: 1, deleted_at: { '$eq': null }, 
status: { '$ne': 3 }}, { skip: 0, limit: 100, sort: { hgf: -1 }, projection: {} });

这应该有效:

files.find({
account_id: 1,
deleted_at: { '$eq': null }, 
status: { '$ne': 3 },
hgf: { $exists: true, $ne: null } // Check it exists and not null
}, { skip: 0, limit: 100, sort: { hgf: -1 }, projection: {} });

最新更新