0% found this document useful (0 votes)
5 views

Mongodb Record

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Mongodb Record

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Program-06 Program -07a

db.students.aggregate([
db.listings.aggregate([
{
{
$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
db.products.aggregate([
db.collection.createIndex({ "email": 1 }, { unique: true
{ })
$project: { db.collection.createIndex({ "age": 1 }, { sparse: true })
_id: 0, db.collection.createIndex({ "name": 1, "age": -1 })
name: 1, db.collection.createIndex({ "tags": 1 })
average_rating: { $avg: "$reviews.rating" },

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

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

},

one_star_reviews: {

$size: {

$filter: {

input: "$reviews",

cond: { $eq: ["$$this.rating", 1] }

])
Program – 09
db.catalog.createIndex({ description: "text" })

db.catalog.find({ $text: { $search: searchWord } })

program -9b
db.catalog.find({ description: { $not: /sale/i } })

db.catalog.find({ description: { $not: /out of stock/i } })

program -10
db.catalog.aggregate([

$match: {

$text: {

$search: "phone"

])

You might also like