我是这里的新手,也是mongodb的新手。我有如下查询:
db.getCollection("devicepositions").aggregate([
{ $match: { portal: new ObjectId("5ecade2d8fdbb1046873af15")}},
{ $group: { _id: "$SerialNumber", ts: { $max: "$Timestamp"} }},
{ $lookup:
{
from: "devicepositions",
let: { sn: "$_id", ts: "$ts"},
pipeline: [
{ $match:
{ $expr:
{ $and:
[
{ $eq: [ "$SerialNumber", "$$sn"] },
{ $eq: [ "$Timestamp", "$$ts" ] }
]
}
}
},
{ $project: {Latitude:1, Longitude:1, Accuracy:1}}
],
as: "position"
}
}
])
结果类似于:
{
"_id" : "4343223323205",
"ts" : ISODate("2020-06-02T19:56:13.353+0000"),
"position" : [
{
"_id" : ObjectId("5ed79b0350869a5738e6a5ac"),
"Latitude" : NumberDecimal("50.9139106"),
"Longitude" : NumberDecimal("10.420745"),
"Accuracy" : NumberInt(1770)
}
]
}
我如何从结果中删除字段类型(NumberInt / ObjectId等...) 预期输出应为:
{
"_id" : "867688036663205",
"ts" : "2020-06-02T19:56:13.353+0000",
"position" : [
{
"_id" : "5ed79b0350869a5738e6a5ac",
"Latitude" : 50.9139106,
"Longitude" : 10.420745,
"Accuracy" : 1770)
}
]
}
请让我朝正确的方向
谢谢