Challenge

Project 2

  1. Write a query to find the average order value for all Customers. SELECT AVG (order) FROM customer;

2.Query your database to get top 10 customers whose orders have the highest value and who have been customers since less than 2 months

d.leads.find({"customer":{$lte:"10"}})

d.leads.find({"order":{$lte:"2"}})

3.Query your database to find the sum of all orders received in this month

db.customer.aggregate([{$group:{_id:"order",Total {$sum:2}}}])

4.SELECT city, COUNT(ID) FROM customer GROUP BY city;

db.inventory.insertOne( { 
    item: "journal", 
    price: 9.99, 
    qty: 25, 
    size: { h: 14, l: 21, w: 1 }, 
    features: "Beautiful, handmade journal.",
    categories: ["writing", "bestseller"],
    image: "items/journal.jpg"  
} )

db.inventory.updateOne( 
    { _id: ObjectId("600e814359ba901629a14e13") }, 
    {
        $unset: {image: 1, size: 1, qty: 1, price: 1},
        $set : { 
            item: "journal", 
            features: ["Inner pocket", "Durable cover"],
            skus: [ { 
                sku: "154A",
                price: {
                    base: NumberDecimal(9.99),
                    currency: "USD"
                },
                quantity: 20,
                options: {
                    size: { h: 14, l: 21, w: 1 },
                    features: ["72 sheets of premium lined paper"],
                    colors: ["brown", "red"],
                    ruling: "wide",
                    image: "images/journal1.jpg"
                }
            }, {
                sku: "154B",
                price: {
                    base: NumberDecimal(14.99),
                    currency: "USD",
                    discount: NumberDecimal(4.00)
                },
                quantity: 15,
                options: { 
                    size: { h: 18, l: 22, w: 2 },
                    features: ["140 sheets of premium paper"],
                    colors: ["brown"],
                    ruling: "unlined",
                    image: "images/journals.jpg"
                }
            } ]
        }
    }
)

db.customers.insertOne( { 
    _id: "journalfanatic@e/mail.com",
    fname: "Journal", 
    lname: "Fanatic",
    hashedAndSaltedPassword: "$1$O3JMY.Tw$AdLnLjQ/5jXF9.MTp3gHv/",
    emailVerified: false,
    address: {
        country: "United States",
        street1: "99 Main Street",
        street2: "Apt #3",
        city: "Boston",
        state: "MA",
        zip: "74586" 
        }
} )
db.customers.updateOne( 
    { _id: "journalfanatic@e/mail.com" },
    { $set: { 
        "address.zip": "60601",
        shippingAddress: { 
            street1: "50 Work Street",
            street2: "Floor 16",
            city: "Chicago",
            state: "IL",
            zip: "60601" } },
     $setOnInsert: { dateModified: new Date() }
    }
)
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.