以下查询返回数据,但 hgf 字段在document(db)中不存在。如何限制仅对现有字段进行排序?
files.find({ account_id: 1, deleted_at: { '$eq': null },
status: { '$ne': 3 }}, { skip: 0, limit: 100, sort: { hgf: -1 }, projection: {} });
答案 0 :(得分:1)
这应该有效:
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: {} });