Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mongoose.aggregate([
- { "$match": { "weekNumber": weekNumber } },
- { "$unwind": "$locations" },
- { "$addFields": { "shifts": "$locations.shifts"}},
- { "$unwind": "$shifts" },
- { "$lookup": {
- "let": { "userObjId": { "$toObjectId": "$shifts.shiftTypeId" } },
- "from": "shiftTypes",
- "pipeline": [
- { "$match" : { "$expr": { "$eq" : [ "$_id", "$$userObjId"] } } }
- ],
- "as": "shiftType"
- }
- },
- { "$addFields": {
- "shifts.name": "$shiftType.name",
- "shifts.color": "$shiftType.color"
- }
- },
- { "$project": {
- "shiftType": 0,
- "locations.shifts": 0
- }
- }
- ])
- [
- {
- _id: ObjectId(),
- "weekNumber": 30,
- "locations": [
- {
- "location": "locationName1",
- "shifts": [
- {
- "shiftTypeId": "shiftType001",
- },
- {
- "shiftTypeId": "shiftType002",
- },
- {
- "shiftTypeId": "shiftType001",
- }
- ]
- },
- {
- "location": "locationName2",
- "shifts": [
- {
- "shiftTypeId": "shiftType001",
- },
- {
- "shiftTypeId": "shiftType002",
- },
- {
- "shiftTypeId": "shiftType001",
- }
- ]
- },
- {
- "location": "locationName3",
- "shifts": [
- {
- "shiftTypeId": "shiftType001",
- },
- {
- "shiftTypeId": "shiftType002",
- },
- {
- "shiftTypeId": "shiftType001",
- }
- ]
- }
- ]
- }
- ]
- [
- {
- _id: ObjectId("shiftType001"),
- "name": "shift001",
- "color": "red"
- },
- {
- _id: ObjectId("shiftType002"),
- "name": "shift002",
- "color": "blue"
- }
- ]
- [
- {
- _id: ObjectId(),
- "weekNumber": 30,
- "locations": [
- {
- "location": "locationName1",
- "shifts": [
- {
- "shiftTypeId": "shiftType001",
- "name": "shift001",
- "color": "red"
- },
- {
- "shiftTypeId": "shiftType002",
- "name": "shift002",
- "color": "blue"
- },
- {
- "shiftTypeId": "shiftType001",
- "name": "shift001",
- "color": "red"
- }
- ]
- },
- {
- "location": "locationName2",
- "shifts": [
- {
- "shiftTypeId": "shiftType002",
- "name": "shift002",
- "color": "blue"
- },
- {
- "shiftTypeId": "shiftType002",
- "name": "shift002",
- "color": "blue"
- },
- {
- "shiftTypeId": "shiftType001",
- "name": "shift001",
- "color": "red"
- }
- ]
- },
- {
- "location": "locationName3",
- "shifts": [
- {
- "shiftTypeId": "shiftType001",
- "name": "shift001",
- "color": "red"
- },
- {
- "shiftTypeId": "shiftType001",
- "name": "shift001",
- "color": "red"
- },
- {
- "shiftTypeId": "shiftType001",
- "name": "shift001",
- "color": "red"
- }
- ]
- }
- ]
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement