How to do inner joining in MongoDB?

后端 未结 4 830
醉梦人生
醉梦人生 2021-02-08 02:31

Is it possible to do SQL inner joins kind of stuff in MongoDB , well i know there is

$lookup

attribute in aggregation pipeline and

4条回答
  •  不知归路
    2021-02-08 03:01

    > show dbs
    admin   0.000GB
    config  0.000GB
    local   0.002GB
    > use local
    switched to db local
    > show collections
    startup_log
    test1
    test2
    > db.test2.aggregate([{
    ...    $lookup: {
    ...       from: "test1",
    ...       localField: "id",
    ...       foreignField: "id",
    ...       as: "aggTest"
    ...    }
    ... }])
    

提交回复
热议问题