Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

join in mongodb

// Join in mongoDB

// Customer table
db.customer.insertMany(
    [
        { "name": "Abhishek", "age": 50, "address": "f/403 anurag", productId: 1 },
        { "name": "raj", "age": 30, "address": "302 Neelmani", productId: 2 },
        { "name": "simran", "age": 70, "address": "rajkot", productId: 3 },
        { "name": "Dhruval", "age": 60, "address": "chennai", productId: 4 }
    ]
)

// Product table
db.product.insertMany(
    [
        { "product_name": "Abhishek", prod_id: 2, "price": 300 },
        { "product_name": "raj", prod_id: 3, "price": 500 },
        { "product_name": "simran", prod_id: 1, "price": 400 },
        { "product_name": "Dhruval", prod_id: 4, "price": 1000 }
    ]
)

// Join using lookUp
db.customer.aggregate([
    {
        $lookup:
        {
            from: "product",
            localField: "productId",
            foreignField: "prod_id",
            as: "productReference"
        }
    }
])
Comment

mongodb join

let videos= await Beg.aggregate([
        {
          $project: {
            _id: 1,
          },
        },
        {
          $lookup: {
            from: "videos",
            localField: "_id",
            foreignField: "begId",
            as: "videos",
          },
        },
      ]);
Comment

PREVIOUS NEXT
Code Example
Javascript :: moment js get french time 20:00:00 
Javascript :: how to get a random statement from an array in javascript 
Javascript :: javascript replaceall 
Javascript :: angular loop through key values in map 
Javascript :: js how to sort strings in array 
Javascript :: add class in element on scroll 
Javascript :: change text in html with javascript 
Javascript :: anagram program in javascript 
Javascript :: looping queryselectorall 
Javascript :: convert utc to pst javascript 
Javascript :: jquery fadeout to fadein 
Javascript :: largest and smallest number in an array 1-100 javascript 
Javascript :: convert a string to number in javascript 
Javascript :: get minutes and seconds of long seconds 
Javascript :: js reverse int in descending order 
Javascript :: javascripti remove int character from string 
Javascript :: js canvas draw image 
Javascript :: mongodb.connect is not a function 
Javascript :: leaflet change marker location 
Javascript :: jquery datatable table header not increasing on expanding 
Javascript :: firebase auth api key not valid. please pass a valid api key 
Javascript :: condition inner populate mongoose 
Javascript :: ubuntu internet speed booster 
Javascript :: firebase admin delete user 
Javascript :: scroll down or up event listener 
Javascript :: how to print console in javascript 
Javascript :: react hook example 
Javascript :: how to deep copy an object in javascript 
Javascript :: javascript replace all string 
Javascript :: reflect javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =