MongoDB - Join on multiple condition

Shibu

For the below query

SQL:

SELECT * FROM TableA as A LEFT JOIN TableB as B ON (A.id = B.id AND A.name =B.name)

Mongo:

TableA.aggregate([
    {"$lookup": {
                "from": "TableB",
                "localField": "_id",
                "foreignField": "_id",
                "as": "b"
                }},
                { "$match": {  "name":"b.name" } }

])

For the above query, required output is not coming.

Gibbs

You could refer this sample playground

db.orders.aggregate([
  {
    "$lookup": {
      from: "inventory",
      let: {
        id: "$_id",
        item: "$item"
      },
      pipeline: [
        {
          "$match": {
            $expr: {
              "$eq": [
                "$_id",
                "$$id"
              ],
              "$eq": [
                "$sku",
                "$$item"
              ]
            }
          }
        }
      ],
      as: "outputs"
    }
  }
])

Reference

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple limit condition in mongodb

From Dev

mongoDB Join on multiple fields

From Dev

Join Table With Multiple Condition Laravel

From Dev

Join Table With Multiple Condition Laravel

From Dev

Filter condition on multiple Join / Inner Join SQL

From Dev

MongoDB multiple condition in WHERE clause

From Dev

Mongodb multiple OR condition on same key

From Dev

MongoDB query with condition on multiple records

From Dev

MongoDB multiple condition in WHERE clause

From Dev

SQL Join on Multiple Tables with Rows Filtered on Condition

From Java

JOIN Multiple Table based on timestamp and another condition

From Dev

MySQL join query with multiple where condition

From Dev

LInq left join with multiple condition in on clause

From Dev

Yii2 - left join on multiple condition

From Dev

Entity Framework: Dynamically generate multiple OR condition on JOIN

From Dev

SQL Join with multiple row condition in second table

From Dev

Linq left outer join with multiple condition

From Dev

Hibernate: Multiple condition on LEFT JOIN using a criteriaBuiler

From Dev

Entity Framework: Dynamically generate multiple OR condition on JOIN

From Dev

Linq expression with multiple joins with condition in each join

From Dev

POSTGRESQL: multiple condition with not exists in one table join

From Dev

distinct with multiple fields and with where condition in mongodb

From Dev

Join with condition

From Dev

Selecting multiple fields using If condition, with left join in mysql - throwing error

From Dev

R Multiple condition join using data.table

From Dev

How to combine another condition with multiple inner join in sql?

From Dev

What is the proper syntax for multiple left join and where condition on the left table?

From Dev

Do Multiple Left Join on condition and get non null column value

From Dev

mysql select multiple avg columns using where in condition and join query

Related Related

  1. 1

    Multiple limit condition in mongodb

  2. 2

    mongoDB Join on multiple fields

  3. 3

    Join Table With Multiple Condition Laravel

  4. 4

    Join Table With Multiple Condition Laravel

  5. 5

    Filter condition on multiple Join / Inner Join SQL

  6. 6

    MongoDB multiple condition in WHERE clause

  7. 7

    Mongodb multiple OR condition on same key

  8. 8

    MongoDB query with condition on multiple records

  9. 9

    MongoDB multiple condition in WHERE clause

  10. 10

    SQL Join on Multiple Tables with Rows Filtered on Condition

  11. 11

    JOIN Multiple Table based on timestamp and another condition

  12. 12

    MySQL join query with multiple where condition

  13. 13

    LInq left join with multiple condition in on clause

  14. 14

    Yii2 - left join on multiple condition

  15. 15

    Entity Framework: Dynamically generate multiple OR condition on JOIN

  16. 16

    SQL Join with multiple row condition in second table

  17. 17

    Linq left outer join with multiple condition

  18. 18

    Hibernate: Multiple condition on LEFT JOIN using a criteriaBuiler

  19. 19

    Entity Framework: Dynamically generate multiple OR condition on JOIN

  20. 20

    Linq expression with multiple joins with condition in each join

  21. 21

    POSTGRESQL: multiple condition with not exists in one table join

  22. 22

    distinct with multiple fields and with where condition in mongodb

  23. 23

    Join with condition

  24. 24

    Selecting multiple fields using If condition, with left join in mysql - throwing error

  25. 25

    R Multiple condition join using data.table

  26. 26

    How to combine another condition with multiple inner join in sql?

  27. 27

    What is the proper syntax for multiple left join and where condition on the left table?

  28. 28

    Do Multiple Left Join on condition and get non null column value

  29. 29

    mysql select multiple avg columns using where in condition and join query

HotTag

Archive