在我的数据库中,我有一个集合,让我们将其命名为"cv“。我使用的是Mongodb的全文搜索。我正在尝试通过mongodb的.sort()函数对查询结果进行排序:
var cvs = await Cv.find({ where: { $text : { search : searchQuery } }, score : { $meta: "textScore" } })
.sort({ score : { $meta : 'textScore' } }); 但是,我得到了这个错误:
TypeError: Cv.find(...).sort不是函数。
发布于 2018-11-29 16:11:53
find是一个仓库方法,而不是model,你必须创建一个仓库。关于排序功能,我认为它在存储库中是不存在的,我认为您可以使用排序过滤器:https://loopback.io/doc/en/lb3/Order-filter.html。
如果没有,您可以在存储库中创建一个排序函数或覆盖find函数。查看此处:https://loopback.io/doc/en/lb4/Repositories.html#example-custom-connector-crud-methods
https://stackoverflow.com/questions/53517419
复制相似问题