Mongodb Record
Mongodb Record
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: {
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" },
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",
])
Program – 09
db.catalog.createIndex({ description: "text" })
program -9b
db.catalog.find({ description: { $not: /sale/i } })
program -10
db.catalog.aggregate([
$match: {
$text: {
$search: "phone"
])