首页 > 解决方案 > 将 SQL 查询转换为等效的 mongodb 查询

问题描述

我需要你们帮助将 SQL 查询转换为 mongodb 查询。

这是我的查询:

select *  
from DocumentDetails 
where OldBatchDesc in (select top 1 OldBatchDesc 
                       from DocumentDetails 
                       where DocumentId = '2d0c4fef-21c8-4089-8e48-103055902741')

标签: sqlmongodb-query

解决方案


所以,伙计们,我终于实现了。为未来的读者提供解决方案。我使用 Robo3t。

db.getCollection('documentdetails').aggregate([
    { "$match": {
        "OldBatchDesc": { 
            "$in": db.getCollection('documentdetails').distinct("OldBatchDesc",{ "DocumentId": "2d0c4fef-21c8-4089-8e48-103055902741" })
        }
    }}
])

推荐阅读