将Postgres查询转换为mongodb查询

时间:2020-06-05 05:48:03

标签: mongodb

我的postgres查询写如下。 Postgres和Mongodb是彼此的镜像。我需要将下面用Postgres编写的查询转换为Mongodb。有关如何进行子查询的任何提示,如下所示

    WITH tests AS (
         SELECT t.test_name AS test,
            count(tag.id) FILTER (WHERE tag.result = 'F' AND (t.result = 'A' OR t.result = 'B')) AS tot_flake_run,
            count(t.run_id) AS tot_runs
           FROM test t
             JOIN testaggregate tag ON tag.id = t.test_aggregate_fk
          WHERE t.pipeline_name = 'PIPELINE_NAME' AND t.end_time IS NOT NULL AND (t.end_time >= now())
          GROUP BY t.test_name
        )
 SELECT w.workload,
    round((w.tot_flake_run * 100 / w.tot_runs), 2) AS flaky
   FROM tests w;

0 个答案:

没有答案