How to use a result from an aggregation query

27 views
Skip to first unread message

Jürgen Stolz

unread,
Apr 20, 2016, 5:28:04 AM4/20/16
to mongodb-user
Hi,

perhaps someone could give me an hint.

This is my (working) query

db.tourMetaDataArchive.aggregate([
 
{$match : {'tour.stops.locationId':'12'}},
 
{$unwind : '$tour.stops'},
 
{$match : {'tour.stops.locationId':'12'} },
 
{$unwind : '$scheduleInfo.stopSchedules'},
 
{$match : {'scheduleInfo.stopSchedules.decryptedCustomerStopSCEMID' : '41Q2Q9SNFR'} }
])

My problem is the hardcoded parameter ('41Q2Q9SNFR') in the last $match, here I want to use the content ('tour.stops.scemid) I received from the second $match ( {$match : {'tour.stops.locationId':'12'} },) .

How could I use parts of the result from this step?

Best wishes 
Jürgen 

Query and result
db.tourMetaDataArchive.aggregate([
 
{$match : {'tour.stops.locationId':'12'}},
 
{$unwind : '$tour.stops'},
 
{$match : {'tour.stops.locationId':'12'} }
])


Result
{ "_id" : ObjectId("56b385d50cb39c7538b23aa6"), "tourMetaData" : { "emCreateTime" : "04.02.2016 16:22:57", "tourStartTime" : "0001-01-01T00:00:00.0000000+00:00", "referenceTime" : "0001-01-01T00:00:00.0000000+00:00", "restStart" : "0001-01-01T00:00:00.0000000+00:00", "restFinish" : "0001-01-01T00:00:00.0000000+00:00", "breakStart" : "0001-01-01T00:00:00.0000000+00:00", "breakFinish" : "0001-01-01T00:00:00.0000000+00:00", "drivenSinceLastBreak" : 0, "zeroTimeAccountRefTime" : "0001-01-01T00:00:00.0000000+00:00", "drivenSinceLastRest" : 0, "currentIdlePeriod" : 0, "isSplitBreak" : false, "isSplitRest" : false, "useRaST" : true, "breakTime" : 0, "lastETACalculation" : "0001-01-01T00:00:00.0000000+00:00", "drivingTime" : "0001-01-01T00:00:00.0000000+00:00", "inBreak" : false, "lastDrivingTime" : "0001-01-01T00:00:00.0000000+00:00", "maxDistInBreak" : 0, "potViolBreak" : false }, "tour" : { "scemid" : "94V82DH1WR", "stops" : { "coordinate" : { "locationX" : 4.47221, "locationY" : 51.95981 }, "locationId" : "12", "earliestArrivalTime" : "2016-02-04T10:00:00.0000000+01:00", "latestDepartureTime" : "2016-02-04T11:00:00.0000000+01:00", "serviceTimeAtStop" : 0, "useServicePeriodForRecreation" : false, "weightWhenLeavingStop" : 0, "stopPositionInTour" : 0, "scemid" : "FXV82DH1WR", "isMongoId" : false, "isUniqueArrayId" : false, "emVersion" : "trunk", "source" : "EM-1284", "emCreateTime" : "2016-02-04T16:22:57.9513565+01:00" }, "vehicle" : { "vehicleProfileID" : "mg-truck-11.99t_wt" }, "drivers" : [ { "driverDescription" : "" } ], "customData" : {  } }, "tourConfig" : { "etaCalcIntrv" : 360 }, "scheduleInfo" : { "stopSchedules" : [ { "decryptedCustomerStopSCEMID" : "FXV82DH1WR", "plannedTime" : "2016-02-04T10:00:00.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-04T18:09:41.7453616+01:00" }, { "decryptedCustomerStopSCEMID" : "BCV82DH1WR", "plannedTime" : "2016-02-04T12:00:00.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-04T18:09:41.7453616+01:00" }, { "decryptedCustomerStopSCEMID" : "48V82DH1WR", "plannedTime" : "2016-02-04T14:00:00.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-04T18:09:41.7453616+01:00" } ], "etaSource" : "PLANNED_TOUR_ETA" }, "tourCreatedJournals" : [ { "ts" : "2016-02-04T15:22:58.4197563+00:00", "journalType" : "TOUR_CREATED", "description" : "Tour created", "entry" : "", "tourSCEMID" : "EMV82DH1WR", "scemid" : "ZKV4HESOSO", "isMongoId" : true, "isUniqueArrayId" : true, "id" : "539744f9d9614816aaf4a5a2011ad087", "emVersion" : "trunk", "_Id" : "{ $oid : 56b382f95c232d0130b2f34d }", "source" : "EM-1284", "emCreateTime" : "2016-02-04T16:23:00.6162079+01:00" } ], "scemid" : "94V82DH1WR", "isMongoId" : true, "isUniqueArrayId" : false, "id" : "EMV82DH1WR", "emVersion" : "trunk", "source" : "EM-1284", "refToken" : "PTV_DiFe_4NNYLL6YHKR2Q3BQ", "emCreateTime" : "2016-02-04T17:09:41.7393567Z" }
{ "_id" : ObjectId("56b46fd95c232a266c6421c3"), "tourMetaData" : { "emCreateTime" : "30.11.2015 10:41:16", "tourStartTime" : "0001-01-01T00:00:00.0000000+00:00", "referenceTime" : "0001-01-01T00:00:00.0000000+00:00", "restStart" : "0001-01-01T00:00:00.0000000+00:00", "restFinish" : "0001-01-01T00:00:00.0000000+00:00", "breakStart" : "0001-01-01T00:00:00.0000000+00:00", "breakFinish" : "0001-01-01T00:00:00.0000000+00:00", "drivenSinceLastBreak" : 0, "zeroTimeAccountRefTime" : "2015-11-30T08:00:00.0000000+01:00", "drivenSinceLastRest" : 0, "currentIdlePeriod" : 0, "isSplitBreak" : false, "isSplitRest" : false, "useRaST" : true, "breakTime" : 0, "lastETACalculation" : "0001-01-01T00:00:00.0000000+00:00", "drivingTime" : "0001-01-01T00:00:00.0000000+00:00", "inBreak" : false, "lastDrivingTime" : "0001-01-01T00:00:00.0000000+00:00", "maxDistInBreak" : 0, "potViolBreak" : false }, "tour" : { "scemid" : "SYQ2Q9SNFR", "stops" : { "coordinate" : { "locationX" : 8.61638888888889, "locationY" : 49.8183333333333 }, "locationId" : "12", "earliestArrivalTime" : "2015-11-30T08:00:00.0000000+01:00", "latestDepartureTime" : "2015-11-30T08:00:00.0000000+01:00", "serviceTimeAtStop" : 0, "useServicePeriodForRecreation" : true, "weightWhenLeavingStop" : 0, "stopPositionInTour" : 0, "scemid" : "41Q2Q9SNFR", "isMongoId" : false, "isUniqueArrayId" : false, "emVersion" : "trunk", "source" : "EM-555", "emCreateTime" : "2015-11-30T10:41:16.5243414+01:00" }, "vehicle" : { "vehicleProfileID" : "mg-trailer-truck" }, "drivers" : [ { "driverDescription" : "driver 1", "raSTime" : { "referenceTime" : "2015-11-30T08:00:00.0000000+01:00", "periodDrivenSinceLastBreak" : 0, "periodDrivenSinceLastRest" : 0, "currentIdlePeriod" : 0, "isSplitBreak" : false, "isSplitRest" : false } } ], "customData" : { "user" : "${customDataUser}", "route" : "1635 - M�rfelden - Hattersheim" } }, "tourConfig" : { "etaCalcIntrv" : 360 }, "scheduleInfo" : { "stopSchedules" : [ { "locationId" : "12", "decryptedCustomerStopSCEMID" : "41Q2Q9SNFR", "plannedTime" : "2015-11-30T08:00:00.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "8CQ2Q9SNFR", "plannedTime" : "2015-11-30T08:29:20.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "83Q2Q9SNFR", "plannedTime" : "2015-11-30T08:49:10.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "URQ2Q9SNFR", "plannedTime" : "2015-11-30T09:12:10.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "PDQ2Q9SNFR", "plannedTime" : "2015-11-30T10:07:40.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "Z7Q2Q9SNFR", "plannedTime" : "2015-11-30T10:38:10.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "3GQ2Q9SNFR", "plannedTime" : "2015-11-30T11:17:30.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "26Q2Q9SNFR", "plannedTime" : "2015-11-30T12:02:00.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "A8Q2Q9SNFR", "plannedTime" : "2015-11-30T12:29:40.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "GSQ2Q9SNFR", "plannedTime" : "2015-11-30T12:53:50.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "2JQ2Q9SNFR", "plannedTime" : "2015-11-30T13:15:00.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "N5Q2Q9SNFR", "plannedTime" : "2015-11-30T13:40:00.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "7YQ2Q9SNFR", "plannedTime" : "2015-11-30T14:06:40.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "DBQ2Q9SNFR", "plannedTime" : "2015-11-30T14:39:20.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "PCQ2Q9SNFR", "plannedTime" : "2015-11-30T14:57:30.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "NJQ2Q9SNFR", "plannedTime" : "2015-11-30T15:35:50.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" }, { "decryptedCustomerStopSCEMID" : "BGQ2Q9SNFR", "plannedTime" : "2015-11-30T17:28:20.0000000+01:00", "refRouteResult" : "0001-01-01T00:00:00.0000000+00:00", "lastETAResult" : "0001-01-01T00:00:00.0000000+00:00", "relatedTime" : "2016-02-05T10:48:09.9336515+01:00" } ], "etaSource" : "PLANNED_TOUR_ETA" }, "tourCreatedJournals" : [ { "ts" : "2015-11-30T09:41:16.5623446+00:00", "journalType" : "TOUR_CREATED", "description" : "Tour created", "entry" : "", "tourSCEMID" : "EMQ2Q9SNFR", "scemid" : "JYN5ZT2ZW4", "isMongoId" : true, "isUniqueArrayId" : true, "id" : "a86632b985d9458c89aea5a300a18b6f", "emVersion" : "trunk", "_Id" : "{ $oid : 56b1c98c0105212e4cf58462 }", "source" : "EM-555", "emCreateTime" : "2015-11-30T10:41:21.2146563+01:00" } ], "tourDeletedJournals" : [ { "ts" : "2015-11-30T09:41:16.6043471+00:00", "journalType" : "TOUR_DELETED", "description" : "Tour deleted", "entry" : "API: Tour delete", "tourSCEMID" : "EMQ2Q9SNFR", "scemid" : "JYN5ZT2ZW4", "isMongoId" : true, "isUniqueArrayId" : true, "id" : "8817ba24124945ceb6dfa5a300a18b6f", "emVersion" : "trunk", "_Id" : "{ $oid : 56b1c98c0105212e4cf58461 }", "source" : "EM-555", "emCreateTime" : "2015-11-30T10:41:16.7353545+01:00" } ], "scemid" : "SYQ2Q9SNFR", "isMongoId" : true, "isUniqueArrayId" : false, "id" : "EMQ2Q9SNFR", "emVersion" : "trunk", "source" : "EM-555", "refToken" : "L5651TJ2G1JTYDN5DVEK3MCRK", "emCreateTime" : "2016-02-05T09:48:09.9306314Z" }




Reply all
Reply to author
Forward
0 new messages