我有两个系列。地点和Archiveloc。我希望在通过某些条件后从位置输入特定文档到archiveloc。然后,在将其转移到Archiveloc后,需要从Locations集合中删除该特定文档。我可以将文档传输到Archiveloc但不能从Locations集合中删除它。以下是我的代码
locations.aggregate([
{
$sort: {
createdAt: -1
}
},
{
$group: {
_id: '$imei',
total_imei: {
$sum: 1,
},
"firstDoc": {
"$first": "$_id",
},
object: {
$push: "$$ROOT",
},
}
},
{
$match: {
total_imei: {
$gt: 2
}
}
},
{
$out: "archiveloc",
}
].exec(function (e, d) {
console.log(d);
d.forEach(function (data) {
console.log(data);
// return temp;
// console.log(temp);
});
}));
快速帮助将不胜感激。提前致谢。
出于测试目的,下面提供了文件示例:
对于名为Locations的集合:
{
"_id" : ObjectId("57010cde76fe39110d716ad0"),
"sourcedevice" : "tcpping",
"imei" : "86669902366722",
"commandtype" : "AAA",
"latitude" : "0.41995433112606406",
"longitude" : "0.43301976611837745",
"datetime" : ISODate("2016-04-03T12:30:22.401Z"),
"status" : "A",
"mileage" : "10418109",
"run_time" : "12854934",
"base_station_info" : "470|1|61E0|43C4",
"io_port_status" : "0000",
"analog_input" : "0000|0000|0000|02D3|010A",
"increment_index" : 1459686622401.0000000000000000,
"__v" : 0}
Archiveloc集合的文档:
{
"_id" : "86669902366722",
"total_imei" : 45,
"firstDoc" : ObjectId("57010cde76fe39110d716ad0"),
"object" : [
{
"_id" : ObjectId("57010cde76fe39110d716ad0"),
"sourcedevice" : "tcpping",
"imei" : "86669902366722",
"commandtype" : "AAA",
"latitude" : "0.41995433112606406",
"longitude" : "0.43301976611837745",
"direction" : "83",
"horizaontal_accuracy" : "0.8",
"altitude" : "6",
"mileage" : "10418109",
"run_time" : "12854934",
"base_station_info" : "470|1|61E0|43C4",
"io_port_status" : "0000",
"analog_input" : "0000|0000|0000|02D3|010A",
"increment_index" : 1459686622401.0000000000000000,
"__v" : 0
}
]}