Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongo db get child result with array of parent ids

db.collection.aggregate([
  {
    $match: {
      tags: "b", // add your search
      childs: { $ne: [] }
    }
  },
  {
    $lookup: {
      from: "collection",
      let: { childs: "$childs" },
      as: "ids",
      pipeline: [
        {
          $match: {
            $expr: { $in: ["$id", "$$childs"] },
            tags: { $ne: "b" } // add your search
          }
        }
      ]
    }
  },
  {
    $project: {
      id: 1,
      ids: {
        $reduce: {
          input: "$ids",
          initialValue: [],
          in: { $concatArrays: ["$$value", ["$$this.id"]] }
        }
      }
    }
  }
])
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript datamatrix parser 
Javascript :: Custom Delimiter For Mustache.js 
Javascript :: echarts js 
Javascript :: audio js fast 
Javascript :: Import Variable From Module In JavaScript 
Javascript :: Remove # id From URL When Clicked On Href Link 
Javascript :: ... Notation In JavaScript 
Javascript :: bullet mechanism in phaser 
Javascript :: javascript server side 
Javascript :: 120. Triangle - JavaScript Solution With Explantion 
Javascript :: yoptascript 
Javascript :: force browser reload page from server javascript 
Javascript :: $faker randomElements 
Javascript :: empty or remove div span class 
Javascript :: communicate between content script and bg 
Javascript :: success res node.js 
Javascript :: nesjs rest api 
Javascript :: add text to each element in an array javascript 
Javascript :: magnetic button vanilla js 
Javascript :: NextJs + Material UI, manually refreshing causes 
Javascript :: required field in javascript dynamically 
Javascript :: discord.js create a private channel 
Javascript :: clear an array 
Javascript :: js check that interactive element is not focused 
Javascript :: how to print reverse number in javascript 
Javascript :: convert jquery to javascript converter online tool 
Javascript :: moment max 
Javascript :: arrow expression javascript 
Javascript :: path js 
Javascript :: js pick last element of array 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =