gpt4 book ai didi

javascript - "TOP N WITH TIES"用于 MongoDB

转载 作者:可可西里 更新时间:2023-11-01 10:28:26 27 4
gpt4 key购买 nike

SQL Server 有一个方便的运算符 "TOP N WITH TIES" , 返回

two or more rows that tie for last place in the limited results set

例如,TOP 3 WITH TIES from {10, 9, 8, 8, 2} 将返回 {10, 9, 8, 8}。

对于 MongoDB,TOP N WITH TIES 是否有等效的单一查询?

我不能使用两个查询(第二个搜索第一个返回的最小值),因为我在 Meteor 发布函数中运行查询,doesn't let you return more than one cursor from the same collection .

最佳答案

您不必返回子查询即可将其用作条件。这基本上与您在任何其他 SQL 引擎中必须做的事情相同。

var min = Collection.find({},{limit:10, sort: {rank: -1}}).fetch()[9].rank
return Collection.find({rank: {$gte: min}})

关于javascript - "TOP N WITH TIES"用于 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30805826/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com