0% found this document useful (0 votes)
12 views3 pages

MongoDB Aggregation & Indexing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

MongoDB Aggregation & Indexing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program-06 Program -07a

[Link]([
[Link]([
{
{
$match: { age: 20 }
$lookup: {
},
from: "hosts",
{
localField: "host_id",
$group: {
foreignField: "_id",
_id: "$grade",
as: "host"
count: { $sum: 1 },
}
averageAge: { $avg: "$age" }
},
}
{
},
$match: {
{
"host.host_picture_url": { $exists: true,
$sort: { count: -1 } $ne: null }

}, }

{ },

$project: { {

_id: 0, $project: {

grade: "$_id", _id: 0,

count: 1, listing_url: 1,

averageAge: 1 name: 1,

} address: 1,

}, host_picture_url:
"$host.host_picture_url"
{
}
$skip: 1
}
}
])
])
Program – 07b
Program – 8a
[Link]([
[Link]({ "email": 1 }, { unique: true
{ })
$project: { [Link]({ "age": 1 }, { sparse: true })
_id: 0, [Link]({ "name": 1, "age": -1 })
name: 1, [Link]({ "tags": 1 })
average_rating: { $avg: "$[Link]" },

total_reviews: { $size: "$reviews" },

five_star_reviews: { Program – 8b
$size: { [Link]({ "author": 1 })
$filter: { [Link]({ "publication_year": 1 })
input: "$reviews", [Link]({ "author": "J.K. Rowling" })
cond: { $eq: ["$$[Link]", 5] } [Link]({ "publication_year": 2005 })
}

},

one_star_reviews: {

$size: {

$filter: {

input: "$reviews",

cond: { $eq: ["$$[Link]", 1] }

])
Program – 09
[Link]({ description: "text" })

[Link]({ $text: { $search: searchWord } })

program -9b
[Link]({ description: { $not: /sale/i } })

[Link]({ description: { $not: /out of stock/i } })

program -10
[Link]([

$match: {

$text: {

$search: "phone"

])

You might also like