Search This Blog

Sunday, 2 March 2025

MONGODB-1

 db.orders.insertMany([

    {

        "order_id": 1,

        "customer_id": "C123",

        "product": "Laptop",

        "quantity": 1,

        "price": 1200,

        "order_date": ISODate("2023-03-01T00:00:00Z"),

        "status": "Shipped"

    },

    {

        "order_id": 2,

        "customer_id": "C124",

        "product": "Phone",

        "quantity": 2,

        "price": 600,

        "order_date": ISODate("2023-03-02T00:00:00Z"),

        "status": "Pending"

    },

    {

        "order_id": 3,

        "customer_id": "C125",

        "product": "Tablet",

        "quantity": 3,

        "price": 400,

        "order_date": ISODate("2023-03-02T00:00:00Z"),

        "status": "Shipped"

    }

])

db.orders.find()

db.orders.find({ "customer_id": "C123" })

db.orders.find({ "order_date": { $gt: ISODate("2023-03-01T00:00:00Z") } })

db.orders.aggregate([

    { $group: { _id: null, totalSales: { $sum: { $multiply: ["$quantity", "$price"] } } } }

])

db.orders.aggregate([

    { $group: { _id: "$product", totalSales: { $sum: { $multiply: ["$quantity", "$price"] } } } }

])

db.orders.aggregate([

    { $group: { _id: "$customer_id", orderCount: { $sum: 1 } } }

])


No comments:

Post a Comment

Hadoop Analytics

BIGLAB-HABSE-1

  Create an HBase Table for Orders Let’s create a table named orders to store the order data. The table will have the following columns: Ro...