عرض عملي: بناء خدمة المراجعات على MongoDB
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
build the reviews service with a ratings summary. Prepares MID-042-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Create the
Reviewdocument and repository; addPOST /products/{id}/reviewsandGETfor the latest 20. - Add the compound index
{ productId: 1, createdAt: -1 }and proveIXSCANwithexplain. - Add
GET /products/{id}/rating-summaryusing an aggregation ($match,$groupaverage and count). - Run it against 100 000 seeded reviews; compare timings with and without the index.
- Planned mistake: embed the review list inside a
ProductReviewsdocument; at a few thousand reviews updates slow down. Fix: one document per review and a separate summary. - Use Testcontainers with a MongoDB image for the integration test (verify image tag).
اختبر فهمك
Where is the average computed?
أظهر الإجابة
In the database, by the aggregation pipeline.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.