How to group random documents?

This is my collection, Just simple post data per document.

[
{
  "title": "This is a title-1",
  "description": "This is a description",
  "imageURL": "https://img.freepik1.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-1-72876078"
},
{
  "title": "This is a title-2",
  "description": "This is a description",
  "imageURL": "https://img.freepik2.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-2-72876078"
},
{
  "title": "This is a title-3",
  "description": "This is a description",
  "imageURL": "https://img.freepik3.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-3-72876078"
},
{
  "title": "This is a title-4",
  "description": "This is a description",
  "imageURL": "https://img.freepik4.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-4-72876078"
},
{
  "title": "This is a title-5",
  "description": "This is a description",
  "imageURL": "https://img.freepik5.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-5-72876078"
},
{
  "title": "This is a title-6",
  "description": "This is a description",
  "imageURL": "https://img.freepik6.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-6-72876078"
},
{
  "title": "This is a title-7",
  "description": "This is a description",
  "imageURL": "https://img.freepik7.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-7-72876078"
},
{
  "title": "This is a title-8",
  "description": "This is a description",
  "imageURL": "https://img.freepik8.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-8-72876078"
},
{
  "title": "This is a title-9",
  "description": "This is a description",
  "imageURL": "https://img.freepik9.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-9-72876078"
},
{
  "title": "This is a title-10",
  "description": "This is a description",
  "imageURL": "https://img.freepik10.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-10-72876078"
},
{
  "title": "This is a title-11",
  "description": "This is a description",
  "imageURL": "https://img.freepik11.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-11-72876078"
},
{
  "title": "This is a title-12",
  "description": "This is a description",
  "imageURL": "https://img.freepik12.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
  "slug": "this-is-a-title-12-72876078"
},
]

How to add random post data of other documents to every document like this:

{
    "title": "This is a title-1",
    "description": "This is a description",
    "imageURL": "https://img.freepik1.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
    "slug": "this-is-a-title-1-72876078",
    "randomPost1": {
      "title": "This is a title-6",
      "description": "This is a description",
      "imageURL": "https://img.freepik6.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
      "slug": "this-is-a-title-6-72876078"
    },
    "randomPost2": {
      "title": "This is a title-9",
      "description": "This is a description",
      "imageURL": "https://img.freepik9.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
      "slug": "this-is-a-title-9-72876078"
    },
    "randomPost3": {
      "title": "This is a title-5",
      "description": "This is a description",
      "imageURL": "https://img.freepik5.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
      "slug": "this-is-a-title-5-72876078"
    },
    "randomPost4": {
      "title": "This is a title-12",
      "description": "This is a description",
      "imageURL": "https://img.freepik12.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
      "slug": "this-is-a-title-12-72876078"
    },
    "randomPost5": {
      "title": "This is a title-8",
      "description": "This is a description",
      "imageURL": "https://img.freepik8.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
      "slug": "this-is-a-title-8-72876078"
    },
    "randomPost6": {
      "title": "This is a title-2",
      "description": "This is a description",
      "imageURL": "https://img.freepik2.com/free-vector/night-ocean-landscape-full-moon-stars-shine_107791-7397.jpg?w=2000",
      "slug": "this-is-a-title-2-72876078"
    }
  }

How can I do this?

Hi @Manish_Sharma10 ,

This can be done with aggregation using $lookup and $sample with a “pipeline lookup” syntax:

db.collection.aggregate([
  {
    "$match": {
      "title": "This is a title-1"
    }
  },
  {
    "$lookup": {
      "from": "collection",
      "pipeline": [
        {
          "$sample": {
            "size": 5
          }
        }
      ],
      "as": "randomPosts"
    }
  }
])

Important the number of random posts is provided to the sample stage. In this one I get 5 random posts.

Ty
Pavel