Node.js Sails.js:如何根据关联集合中的值查找记录?

Node.js Sails.js:如何根据关联集合中的值查找记录?,node.js,mongodb,sails.js,waterline,Node.js,Mongodb,Sails.js,Waterline,我正在寻找一种使用Sails.js Waterline进行子查询的方法。该记录与费用模型有关联 我希望这样的事情能够奏效,但这似乎没有得到支持: var topRecords = await Record.find({'charge.paid':true}); 我得到的最接近的结果是: var topRecords = await Record.find().populate('charge',{paid:true}); 但问题是它仍然返回所有记录,只是不填充与populatewhere语句

我正在寻找一种使用Sails.js Waterline进行子查询的方法。该记录与费用模型有关联

我希望这样的事情能够奏效,但这似乎没有得到支持:

var topRecords = await Record.find({'charge.paid':true});
我得到的最接近的结果是:

var topRecords = await Record.find().populate('charge',{paid:true});
但问题是它仍然返回所有记录,只是不填充与populatewhere语句不匹配的记录


我无法首先搜索费用的原因是我想根据记录中的一个值对数据进行排序。

您可以获取
费用
s,然后使用
.map
从中获取记录

const topCharges = await Charge.find({ paid: true }).populate('records');
const topRecords = topCharges.map(charge => charge.record);

然后,您将如何根据Records collection或CreatedAt中的喜好对topRecords进行排序?我已经使用lodash实现了排序!忽略我的评论