Compare commits

..

No commits in common. "1cb7322a0d3872034c9e605d0906f5b4b14e116d" and "37fc21421dd8a2bc21910e4059dce66ff6ee61b8" have entirely different histories.

4 changed files with 3 additions and 108 deletions

View File

@ -152,7 +152,7 @@ db.Employee.insertMany([
db.Employee.find({ Designation: "Programmer", Salary: { $gt: 30000 } })
```
2. Create a new document if no document contains `{Designation: "Tester", Company_name: "Y-Space", Age: 25}`:
2. Create a new document if no document contains `{Designation: "Tester", Company_name: "TCS", Age: 25}`:
```mongodb
db.Employee.update(
{ Designation: "Tester", Company_name: "Y-Space", Age: 25 },
@ -174,7 +174,7 @@ db.Employee.find({ Address: { $elemMatch: { city: "Pune", Pin_code: "411001" } }
```
5. Find all documents with Company_name "Oscorp" and modify their salary by 2000:
5. Find all documents with Company_name "TCS" and modify their salary by 2000:
```mongodb
db.Employee.updateMany(
{ Company_name: "Oscorp" },
@ -189,7 +189,7 @@ db.Employee.find({ Designation: { $ne: "Developer" } })
```
7. Find _id, Designation, Address, and Name where Company_name is "Wayne Industries":
7. Find _id, Designation, Address, and Name where Company_name is "Infosys":
```mongodb
db.Employee.find(
{ Company_name: "Wayne Industries" },

View File

@ -1,105 +0,0 @@
## Queries-B3
> [!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 the Total Salary of per Company
```mongodb
db.Employee.mapReduce(
function() {
emit(this.Company_name, this.Salary);
},
function(key, values) {
return Array.sum(values);
},
{ out: "total_salary_per_company" }
);
```
2. Return the Total Salary of Company Name:"Oscorp"
```mongodb
db.Employee.mapReduce(
function() {
if (this.Company_name === "Oscorp") {
emit(this.Company_name, this.Salary);
}
},
function(key, values) {
return Array.sum(values);
},
{ out: "total_salary_oscorp" }
);
```
3. Return the Avg Salary of Company whose address is “Pune".
```mongodb
db.Employee.mapReduce(
function() {
if (this.Address.some(addr => addr.PAddr.includes("Pune"))) {
emit("Pune", this.Salary);
}
},
function(key, values) {
return Array.avg(values);
},
{ out: "avg_salary_pune" }
);
```
4. Return the Total Salary for each Designation of `Wayne Industries`.
```mongodb
db.Employee.mapReduce(
function() {
if (this.Company_name === "Wayne Industries") {
emit(this.Designation, this.Salary);
}
},
function(key, values) {
return Array.sum(values);
},
{ out: "total_salary_wayne" }
);
```
5. Return total count for “State=Maharashtra”
```mongodb
db.Employee.mapReduce(
function() {
this.Address.forEach(function(addr) {
if (addr.LAddr === "Maharashtra") {
emit("Maharashtra", 1);
}
});
},
function(key, values) {
return Array.sum(values);
},
{ out: "count_state_maharashtra" }
);
```
6. Return Count for State Telangana and Age greater than 40.
```mongodb
db.Employee.mapReduce(
function() {
if (this.Age > 40) {
this.Address.forEach(function(addr) {
if (addr.LAddr === "Telangana") {
emit("Telangana_Age_Above_40", 1);
}
});
}
},
function(key, values) {
return Array.sum(values);
},
{ out: "count_telangana_age_above_40" }
);
```