İç içe dizi öğesi kendisini Mongodb içinde toplayabilir mi? Örneğin. Ham veriaggregation nested Dizi elemanının kendisi mongodb
{"transId" : "12345","customer" : "cust1", "product" : [{"type" : "cloth","price" : 100},{"type" : "toy","price" : 200}]}
{"transId" : "45672","customer" : "cust1", "product" : [{"type" : "cloth","price" : 10},{"type" : "toy","price" : 500}]}
{"transId" : "99999","customer" : "cust2", "product" : [{"type" : "cloth","price" : 40},{"type" : "toy","price" : 5}]}
iç içe dizi elemanının her istiyoruz
müşteri tarafından tipine göre toplanır ör
Sonuç:
{"customer" : "cust1", "product" : [{"type" : "cloth","price" : 110},{"type" : "toy","price" : 700}]}
{"customer" : "cust2", "product" : [{"type" : "cloth","price" : 40},{"type" : "toy","price" : 5}]}
nasıl yaptığını bana göstermek için yardım eder misiniz? Teşekkürler.
Bir eklenmesini: döndüren
. İstenen formatla uyumlu hale getirmek için toplama hattına {$ project: {_ id: 0, müşteri: "$ _ id", ürün: 1}} 'ekleyin. – Saleem
@Saleem No! '$ project' ekleme, performans düşüşüne neden olur. – styvane