Added new line in each code block to automatically execute on copy.
This commit is contained in:
parent
acc16d556c
commit
9a0ec431bb
@ -1,6 +1,10 @@
|
|||||||
## Queries
|
## Queries-B2
|
||||||
|
|
||||||
### A
|
### Group A
|
||||||
|
|
||||||
|
> ![NOTE]
|
||||||
|
> Use Employee database created in Assignment B-01 and perform following aggregation operation
|
||||||
|
> Refer [Queries-B1](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-B1/Queries-B1.md)
|
||||||
|
|
||||||
1. Return Designation with Total Salary Above 200000:
|
1. Return Designation with Total Salary Above 200000:
|
||||||
```mongodb
|
```mongodb
|
||||||
@ -17,6 +21,7 @@ db.Employee.aggregate([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Find Employee with Total Salary for Each City with Designation "DBA":
|
2. Find Employee with Total Salary for Each City with Designation "DBA":
|
||||||
@ -32,6 +37,7 @@ db.Employee.aggregate([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Find Total Salary of Employee with Designation "DBA" for Each Company:
|
3. Find Total Salary of Employee with Designation "DBA" for Each Company:
|
||||||
@ -47,6 +53,7 @@ db.Employee.aggregate([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Returns Names and _id in Upper Case and in Alphabetical Order:
|
4. Returns Names and _id in Upper Case and in Alphabetical Order:
|
||||||
@ -62,11 +69,13 @@ db.Employee.aggregate([
|
|||||||
$sort: { Name: 1 }
|
$sort: { Name: 1 }
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Count All Records from Collection:
|
5. Count All Records from Collection:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.countDocuments()
|
db.Employee.countDocuments()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
6. For Each Unique Designation, Find Avg Salary and Output Sorted by AvgSal:
|
6. For Each Unique Designation, Find Avg Salary and Output Sorted by AvgSal:
|
||||||
@ -82,6 +91,7 @@ db.Employee.aggregate([
|
|||||||
$sort: { AvgSalary: 1 }
|
$sort: { AvgSalary: 1 }
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
7. Return Separate Value in the Expertise Array Where Name of Employee is "Swapnil":
|
7. Return Separate Value in the Expertise Array Where Name of Employee is "Swapnil":
|
||||||
@ -97,6 +107,7 @@ db.Employee.aggregate([
|
|||||||
$project: { Expertise: 1 }
|
$project: { Expertise: 1 }
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
8. Return Separate Value in the Expertise Array and Return Sum of Each Element of Array:
|
8. Return Separate Value in the Expertise Array and Return Sum of Each Element of Array:
|
||||||
@ -112,6 +123,7 @@ db.Employee.aggregate([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
9. Return Array for Designation Whose Address is "Pune":
|
9. Return Array for Designation Whose Address is "Pune":
|
||||||
@ -124,6 +136,7 @@ db.Employee.aggregate([
|
|||||||
$project: { Designation: 1 }
|
$project: { Designation: 1 }
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
10. Return Max and Min Salary for Each Company:
|
10. Return Max and Min Salary for Each Company:
|
||||||
@ -137,41 +150,54 @@ db.Employee.aggregate([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### B
|
### Group B
|
||||||
|
|
||||||
|
> ![NOTE]
|
||||||
|
> Use Employee database created in Assignment B-01 and perform following aggregation operation
|
||||||
|
> Refer [Queries-B1](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-B1/Queries-B1.md)
|
||||||
|
|
||||||
|
|
||||||
1. Create Single Field Indexes on Designation:
|
1. Create Single Field Indexes on Designation:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.createIndex({ Designation: 1 })
|
db.Employee.createIndex({ Designation: 1 })
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Create Compound Indexes on Name and Age:
|
2. Create Compound Indexes on Name and Age:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.createIndex({ "Name.FName": 1, Age: -1 })
|
db.Employee.createIndex({ "Name.FName": 1, Age: -1 })
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Create Multikey Indexes on Expertise Array:
|
3. Create Multikey Indexes on Expertise Array:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.createIndex({ Expertise: 1 })
|
db.Employee.createIndex({ Expertise: 1 })
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Return a List of All Indexes on Collection:
|
4. Return a List of All Indexes on Collection:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.getIndexes()
|
db.Employee.getIndexes()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Rebuild Indexes:
|
5. Rebuild Indexes:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.reIndex()
|
db.Employee.reIndex()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
6. Drop Index on Remove Specific Index:
|
6. Drop Index on Remove Specific Index:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.dropIndex("empIndex")
|
db.Employee.dropIndex("empIndex")
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
7. Remove All Indexes Except for the _id Index from a Collection:
|
7. Remove All Indexes Except for the _id Index from a Collection:
|
||||||
```mongodb
|
```mongodb
|
||||||
db.Employee.dropIndexes()
|
db.Employee.dropIndexes()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user