Advertisement
ListonFermi

Boarding Week 2 Practical Workouts- Mongodb

Aug 21st, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | Source Code | 0 0
  1. Sample document:
  2.  
  3. {
  4. "_id": "6551bd811f1795355ba843ed",
  5. "index": 14,
  6. "name": "Wendy Sampson",
  7. "isActive": true,
  8. "registered": {
  9. "$date": "2017-03-28T04:46:20.000Z"
  10. },
  11. "age": 18,
  12. "gender": "female",
  13. "eyeColor": "blue",
  14. "favoriteFruit": "strawberry",
  15. "company": {
  16. "title": "BUGSALL",
  17. "email": "[email protected]",
  18. "phone": "+1 (822) 433-3614",
  19. "location": {
  20. "country": "France",
  21. "address": "864 Times Placez"
  22. }
  23. },
  24. "tags": [
  25. "non",
  26. "sunt",
  27. "officia"
  28. ]
  29. }
  30.  
  31.  
  32. db.people.updateMany({},{ $inc:{ age: -2 }})
  33.  
  34. db.people.aggregate([ {$group: { _id: '$eyeColor', count: { $sum: 1 } }} ] )
  35.  
  36.  
  37. Sample document - ordersl collection:
  38. {
  39. "_id": "64b59a5e2c8e7e9c5b8b4567",
  40. "orderNumber": "A123",
  41. "customerId": {
  42. "$oid": "64b59a5e2c8e7e9c5b8b4568"
  43. },
  44. "orderDate": {
  45. "$date": "2024-08-20T14:00:00.000Z"
  46. },
  47. "totalAmount": 1500
  48. }
  49.  
  50. Sample document - customers collection:
  51. {
  52. "_id": 64b59a5e2c8e7e9c5b8b4569",
  53. "name": "Bob Smith",
  54. "email": "[email protected]",
  55. "phone": "+0987654321"
  56. }
  57.  
  58.  
  59. db.ordersl.aggregate([{$lookup:{ from: 'customers' , localField: 'customerId', foreignField: '_id', as: 'CustomerData' }}])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement