I’m trying to get only the subdocument with specific criteria to be returned in a query from mini-mongo.
Structured like
{
"_id" : "vNEZYJqBB5Ww43W26",
"quickCallNo" : 2,
"callNo" : "20171002-032704",
"location" : "8021 SAMUEL L CLEMENS PKWY, DALLAS, TX",
"type" : "Fire",
"priority" : "High",
"priorityColor" : "#cb9c19",
"callers" : [ ],
"firstOnScene" : ISODate("2017-10-02T20:40:55.544Z"),
"transport" : [
{
"unitNo" : "PUMPER1",
"startType" : "In Custody",
"startDest" : "100 MAIN",
"startDesc" : "Hospital",
"startMileage" : 12,
"endMileage" : 9,
"active" : false,
"startedBy" : "bmcgonag",
"startedOn" : ISODate("2017-10-25T17:16:26.399Z")
},
{
"unitNo" : "PUMPER1",
"startType" : "Med to Safe Zone",
"startDest" : "808 Samson DR, Biloxi, MS",
"startDesc" : "Medical transport to safe zone.",
"startMileage" : 14,
"endMileage" : "",
"active" : true,
"startedBy" : "bmcgonag",
"startedOn" : ISODate("2017-10-25T20:23:06.247Z")
},
{
"unitNo" : "TT1",
"startType" : "Med to Safe Zone",
"startDest" : "2nd Hospital run",
"startDesc" : "Back to Hospital",
"startMileage" : 23,
"endMileage" : 12,
"active" : false,
"startedBy" : "bmcgonag",
"startedOn" : ISODate("2017-10-25T20:38:09.498Z")
},
{
"unitNo" : "TT1",
"startType" : "Med to Safe Zone",
"startDest" : "med",
"startDesc" : "med",
"startMileage" : 43,
"endMileage" : "",
"active" : true,
"startedBy" : "bmcgonag",
"startedOn" : ISODate("2017-10-25T20:42:58.377Z")
}
],
}
I’d like to get back on the sub-document where a callSign matches, and active = true.
I’ve been trying
Calls.findOne({ "active": true, "transport": { "$elemMatch": { "unitNo": callSign, "active": true }}}, { fields: { "transport.startDest":1, "transport.startMileage":1 }});
That brings back only the sub-documents, but not only the one I want.
So then I found this on stack-overflow
Calls.findOne({ "active": true, "transport": { "$elemMatch": { "unitNo": callSign, "active": true }}}, { fields: { "transport.$":1 }});
In meteor mongo
this works perfectly, but in MiniMongo i get the error
Uncaught Error: Minimongo doesn’t support $ operator in projections yet.
at MinimongoError (http://localhost:3000/packages/minimongo.js?hash=71a1410dbbd0ac70fea76b0a1103dfc61259a791:93:11)
Is there some way to get this done in Minimongo?
I’m needing the start mileage value of a specific unitNo with active true, and there could be multiple different cunitno with active true, just not the same unitNo with active true more than once.
As always, any help is appreciated.