【发布时间】:2020-06-14 09:00:29
【问题描述】:
我在 mongodb 上有两个文档,分别是 percentages 和 items。我擅长 SQL,我可以编写如下 PLSql 查询但我无法转换为 mongodb 查询。因为我的mongodb知识水平还处于起步阶段。
实际上,我知道我必须将 $gt 用于 and 条件。但我不知道我怎么能说 mongodb 的不存在或 union 关键字。如何编写 mongodb 查询?我应该搜索哪些关键字?
select p.*, "to_top" as list
from percentages p
where p.percentage > 5
and p.updatetime > sysdate - 1/24
and not exists (select 1
from items i
where i.id = p.p_id
and i.seller = p.seller)
order by p.percentage desc
union
select p2.*, "to_bottom" as list
from percentages p2
where p2.percentage > 5
and p2.updatetime > sysdate - 1/24
and exists (select 1
from items i2
where i2.id = p2.p_id
and i2.seller = p2.seller)
order by p2.percentage desc
【问题讨论】:
-
你的收藏看起来像什么,你想要的对应输出是什么?
标签: sql mongodb mongoose mongodb-query aggregation-framework