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.
işleci $sqrt , belirtilen sayının karekökünü hesaplamak için kullanılır.
Syntax
{
$sqrt: <expression>
}
Parameters
| Parametre | Description |
|---|---|
<expression> |
Bir sayıya çözümleyen geçerli ifadeler. |
Examples
Stores koleksiyonundaki bu örnek belgeyi göz önünde bulundurun.
{
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
"name": "First Up Consultants | Beverage Shop - Satterfieldmouth",
"location": {
"lat": -89.2384,
"lon": -46.4012
},
"staff": {
"totalStaff": {
"fullTime": 8,
"partTime": 20
}
},
"sales": {
"totalSales": 75670,
"salesByCategory": [
{
"categoryName": "Wine Accessories",
"totalSales": 34440
},
{
"categoryName": "Bitters",
"totalSales": 39496
},
{
"categoryName": "Rum",
"totalSales": 1734
}
]
},
"promotionEvents": [
{
"eventName": "Unbeatable Bargain Bash",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 6,
"Day": 23
},
"endDate": {
"Year": 2024,
"Month": 7,
"Day": 2
}
},
"discounts": [
{
"categoryName": "Whiskey",
"discountPercentage": 7
},
{
"categoryName": "Bitters",
"discountPercentage": 15
},
{
"categoryName": "Brandy",
"discountPercentage": 8
},
{
"categoryName": "Sports Drinks",
"discountPercentage": 22
},
{
"categoryName": "Vodka",
"discountPercentage": 19
}
]
},
{
"eventName": "Steal of a Deal Days",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 9,
"Day": 21
},
"endDate": {
"Year": 2024,
"Month": 9,
"Day": 29
}
},
"discounts": [
{
"categoryName": "Organic Wine",
"discountPercentage": 19
},
{
"categoryName": "White Wine",
"discountPercentage": 20
},
{
"categoryName": "Sparkling Wine",
"discountPercentage": 19
},
{
"categoryName": "Whiskey",
"discountPercentage": 17
},
{
"categoryName": "Vodka",
"discountPercentage": 23
}
]
}
]
}
Örnek 1: Satışların karekökünü hesaplayın
"First Up Consultants" şirketi altındaki her bir mağazanın satış hacimlerinin karekökünü hesaplamak için önce depoları şirket adına göre filtrelemek için bir sorgu çalıştırın. Ardından, istenen sonuçları almak için totalSales alanındaki $sqrt işlecini kullanın.
db.stores.aggregate([{
$match: {
company: {
$in: ["First Up Consultants"]
}
}
}, {
$project: {
name: 1,
"sales.revenue": 1,
categoryName: "$promotionEvents.discounts.categoryName",
sqrtFullSales: {
$sqrt: "$sales.revenue"
}
}
}])
Bu sorgu tarafından döndürülen ilk iki sonuç şunlardır:
[
{
"_id": "c52c9f65-5b1a-4ef5-a7a2-d1af0426cbe4",
"name": "First Up Consultants | Jewelry Pantry - Nicolasberg",
"sales": {
"revenue": 4624
},
"categoryName": [
[
"Watches",
"Bracelets"
],
[
"Brooches",
"Necklaces"
],
[
"Charms",
"Brooches"
],
[
"Brooches",
"Anklets"
],
[
"Earrings",
"Anklets"
]
],
"sqrtFullSales": 68
},
{
"_id": "176aa484-c21c-44ce-ab6d-5e097bbdc2b4",
"name": "First Up Consultants | Medical Supply Shop - Daughertyville",
"sales": {
"revenue": 67311
},
"categoryName": [
[
"First Aid Kits",
"OTC Medications"
],
[
"Blood Pressure Monitors",
"OTC Medications"
],
[
"Face Masks",
"Stethoscopes"
]
],
"sqrtFullSales": 259.44363549719236
}
]
İ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.