Giter VIP home page Giter VIP logo

mongoose-practice's Introduction

mongoose Practice Aggregation

Example data:

[
   {
     "name": "John Doe",
     "email": "[email protected]",
     "age": 28,
     "address": {
       "street": "123 Main St",
       "city": "New York",
       "state": "NY",
       "zipcode": "10001"
     },
     "favorites": {
       "color": "blue",
       "food": "pizza",
       "movie": "The Shawshank Redemption"
     },
     "friends": [
       {
         "name": "Jane Smith",
         "email": "[email protected]"
       },
       {
         "name": "Mike Johnson",
         "email": "[email protected]"
       }
     ]
   },
   {
     "name": "Alice Williams",
     "email": "[email protected]",
     "age": 35,
     "address": {
       "street": "456 Elm St",
       "city": "San Francisco",
       "state": "CA",
       "zipcode": "94101"
     },
     "favorites": {
       "color": "green",
       "food": "sushi",
       "movie": "The Godfather"
     },
     "friends": [
       {
         "name": "Bob Anderson",
         "email": "[email protected]"
       },
       {
         "name": "Emily Davis",
         "email": "[email protected]"
       }
     ]
   }
 ]

Task 1: Find all users who are located in New York.

Task 2: Find the user(s) with the email "[email protected]" and retrieve their favorite movie.

Task 3: Find all users with "pizza" as their favorite food and sort them according to age.

Task 4: Find all users over 30 whose favorite color is "green".

Task 5: Count the number of users whose favorite movie is "The Shawshank Redemption."

Task 6: Update the zipcode of the user with the email "[email protected]" to "10002".

Task 7: Delete the user with the email "[email protected]" from the user data.

Task 8: Group users by their favorite movie and retrieve the average age in each movie group.

Task 9: Calculate the average age of users with a favorite " pizza " food.

// orders
[
  {
    "_id": 1,
    "order_number": "ORD-001",
    "customer_id": 1,
    "total_amount": 100.0
  },
  {
    "_id": 2,
    "order_number": "ORD-002",
    "customer_id": 2,
    "total_amount": 150.0
  },
  {
    "_id": 3,
    "order_number": "ORD-003",
    "customer_id": 1,
    "total_amount": 200.0
  }
]

// customers
[
  {
    "_id": 1,
    "name": "Alice Williams",
    "email": "[email protected]"
  },
  {
    "_id": 2,
    "name": "Bob Anderson",
    "email": "[email protected]"
  },
  {
    "_id": 3,
    "name": "Emily Davis",
    "email": "[email protected]"
  }
]

Task 10: Perform a lookup aggregation to retrieve the orders data along with the customer details for each order.

More Tasks on Aggregation

Task 1: Group users by their favorite color and retrieve the count of users in each color group.

Task 2: Find the user(s) with the highest age.

Task 3: Find the most common favorite food among all users.

Task 4: Calculate the total count of friends across all users.

Task 5: Find the user(s) with the longest name.

Task 6: Calculate each state's total number of users in the address field.

Task 7: Find the user(s) with the highest number of friends.

These tasks involve using various aggregation operators such as $group, $avg, $max, $sum, and $project to perform complex calculations and data transformations. You can write MongoDB aggregation queries to accomplish each task based on user data. Adjust the queries according to your specific implementation and requirements.

mongoose-practice's People

Contributors

sec-masum avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.