【发布时间】:2021-08-21 03:12:28
【问题描述】:
最近,我将我的 postgreSQL 数据库迁移到了 MongoDB。假设我在 PostgreSQL 中有 2 个表并迁移成为 MongoDB 中的 2 个集合。 在 PostgreSQL 中:
-
表账号代码
ac_id desc group_id p_code c_code 999.01 PettyCash 9 42000 99000 888.09 Tax 34 70000 66000 999.02 PC2 9 43000 99000 -
表事务
reffNum ac_id db cr desc dateTime id audited GL/0003845/V/11/21/XXX 999.01 950000 0 Transfer from Client 2021-03-17 09:58:41.304302 2 0 GL/0005584/V/11/21/XXX 999.02 10000 0 Transfer from Client 2021-03-18 09:58:41.304302 2 0 SL/00077898/V/11/21/XXX 888.09 997500 0 Tax 2021-03-18 09:58:41.304302 2 0 GL/0005485/V/11/21/XXX 999.01 0 150000 Transfer to Client 2021-03-25 09:58:41.304302 3 0
我有这样的 SQL 查询:
SELECT CASE WHEN (SUM (A .db) - SUM (A .cr)) is NULL THEN '0' ELSE (SUM (A .db) - SUM (A .cr)) END from transaction a, accountCode b
where a.ac_id = b.ac_id and a.id<>0 AND (a.audited='0') AND to_char(a.dateTime,'YYYY-MM') = '2021-03' AND b.groupid="9"
它应该给出结果:810000
我将数据库迁移到 MongoDB 中的 2 个集合,类似于 PostgreSQL 中的 2 个表。但是现在,我很困惑如何查询,所以我在 MongoDB 中有相同的结果?或者我应该将结构从 2 个表更改为 MongoDB 中的 1 个单个集合?任何想法? TIA。
【问题讨论】:
标签: mongodb postgresql select where-clause