Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose lookup array of objects

db.players.aggregate([
  { $unwind: "$items" },
  {
    $lookup: {
      from: "items",
      let: {
        itemId: { $toObjectId: "$items.itemId" },
        items: "$items"
      },
      pipeline: [
        { $match: { $expr: { $eq: ["$_id", "$$itemId" ] } } },
        { $replaceRoot: { newRoot: { $mergeObjects: ["$$items", "$$ROOT"] } } }
      ],
      as: "items"
    }
  },
  {
    $group: {
      _id: "$_id",
      username: { $first: "$username" },
      items: { $push: { $first: "$items" } }
    }
  }
])
Comment

PREVIOUS NEXT
Code Example
Javascript :: Sorting Array of String, Numbers or Objects in javascript 
Javascript :: lwc reduceErrors showtoast 
Javascript :: js two operations in ternary 
Javascript :: javascript convert color string to rgb 
Javascript :: ajax file upload 
Javascript :: convert html table to pdf 
Javascript :: js create an object from another object with some keys removed 
Javascript :: Nested Components 
Javascript :: javascript change favicon dynamicly 
Javascript :: index wise print elemnet in javascript 
Javascript :: starting: intent error type 3 react-native 
Javascript :: jquery code convert into javascript online 
Javascript :: addeve 
Javascript :: javascript detect if active element is writable 
Javascript :: Uncaught TypeError: document.getElementById(...).exitFullscreen is not a function 
Javascript :: rest object javascript 
Javascript :: multply js 
Javascript :: how to use handlebars.registerhelper if null 
Javascript :: nodejs mysql Getting the number of affected rows 
Javascript :: Plumsail - DataTable Cascading Dropdowns 
Javascript :: nav hover add class and remove using javascript smooth 
Javascript :: Nyadorera 
Javascript :: hide navbar and footer on certain pages like dashboard. react-router 
Javascript :: trying to minimalize the js code and want to increase the performance speed in js 
Javascript :: angularjs How to sort a specific value in a map 
Javascript :: Conditional navigation inside Tabs 
Javascript :: Undefined value document.getElementById 
Javascript :: PAN SNAP 
Javascript :: get copied text javascript 
Javascript :: echarts js 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =