Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
$concatArrays işleci, birden çok diziyi tek bir dizide birleştirmek için kullanılır. Bu işleç, bir belgedeki farklı belgelerden veya alanlardan dizileri birleştirmeniz gerektiğinde kullanışlıdır.
Sözdizimi
{
$concatArrays: ["<array1>", "<array2>"]
}
Parametreler
| Parametre | Description |
|---|---|
<array1>, <array2> |
Birleştirme için hedeflenen dizi alanları. |
Örnekler
Stores koleksiyonundaki bu örnek belgeyi göz önünde bulundurun.
{
"_id": "7954bd5c-9ac2-4c10-bb7a-2b79bd0963c5",
"name": "Lakeshore Retail | DJ Equipment Stop - Port Cecile",
"location": {
"lat": 60.1441,
"lon": -141.5012
},
"staff": {
"totalStaff": {
"fullTime": 2,
"partTime": 0
}
},
"sales": {
"salesByCategory": [
{
"categoryName": "DJ Headphones",
"totalSales": 35921
},
{
"categoryName": "DJ Cables",
"totalSales": 1000
}
],
"fullSales": 3700
},
"promotionEvents": [
{
"eventName": "Bargain Blitz Days",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 3,
"Day": 11
},
"endDate": {
"Year": 2024,
"Month": 2,
"Day": 18
}
},
"discounts": [
{
"categoryName": "DJ Turntables",
"discountPercentage": 18
},
{
"categoryName": "DJ Mixers",
"discountPercentage": 15
}
]
},
{
"eventName": "Discount Delight Days",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 5,
"Day": 11
},
"endDate": {
"Year": 2024,
"Month": 5,
"Day": 18
}
}
}
],
"tag": [
"#ShopLocal",
"#FashionStore",
"#SeasonalSale",
"#FreeShipping",
"#MembershipDeals"
]
}
Örnek 1: Belgedeki Dizileri Birleştirme
Bu sorgu dizideki categoryNamepromotionEvents.discounts alanı diziyle tag tek bir combinedTags dizisiyle birleştirir.
db.stores.aggregate([{
$match: {
_id: "7954bd5c-9ac2-4c10-bb7a-2b79bd0963c5"
}
}, {
$project: {
combinedTags: {
$concatArrays: ["$promotionEvents.discounts.categoryName", "$tag"]
}
}
}])
Bu sorgu aşağıdaki sonucu döndürür.
[
{
"_id": "7954bd5c-9ac2-4c10-bb7a-2b79bd0963c5",
"combinedTags": [ '#ShopLocal', '#NewArrival', '#NewArrival', '#FreeShipping' ]
}
]
İlgili içerik
- MongoDB'den Azure DocumentDB'ye geçiş seçeneklerini gözden geçirin.
- MongoDB ile özellik uyumluluğu hakkında daha fazla bilgi edinin.