Oracle SQL在mongoDB中不存在等价物

时间:2015-12-17 09:46:17

标签: mongodb mongodb-query

如何在mongodb中编写下面的sql等价查询

select a.id from test a
where not exists(select 1 from test b where b.id=a.id and b.name<>a.name)

请咨询

1 个答案:

答案 0 :(得分:0)

您可以使用$ lookup语法,例如:

    db.collection_A.aggregate([
        {
            "$lookup": {
                "from": "collection_B",
                "localField": "_id",
                "foreignField": "_id",
                "as": "references"
            }
        }, {
            "$match": {
                "references": []
            }
        }
    ])