{
"_id" : ObjectId("5e8dae610b209222e10a0ac4"),
"serial" : "2248",
"externalId" : "452085",
"hierarchyPathByIds" : ",5e2eb1662698a2097c71d855,",
"status" : "ACTIVE",
}
device_events collection {
{
"_id" : ObjectId("5e9d863a235721333eddfb81"),
"deviceId" : "5e8dae610b209222e10a0ac4",
"type" : "PACKAGE_TEST",
"createdAt" : ISODate("2020-04-20T11:04:27.943Z")
}
참고-> 디바이스 콜렉션에 이벤트가없는 경우 두 콜렉션에서 동일한 디바이스 ID를 가진 문서를 가져와야합니다. 결과적으로 발생하지 않습니다. 장치 이벤트는 지난 1 시간 동안도 필터링되어야합니다. 1. 디바이스 이벤트 생성 날짜에있는 모든 디바이스를 내림차순으로 가져와야합니다. 2. hierarchyPathByIds 정규식 패턴이 '. , 5e2eb1662698a2097c71d855 ,. '
장치에 많은 장치 이벤트가 있습니다.
장치 컬렉션 deviceId
으로 저장하기 때문에 String
변환해야합니다.
옵션 1 개 변환은 _ID ObjectId
에 String
의 장치 모음
db.device.aggregate([
{
$project: {
"_id": {
"$toString": "$_id"
},
serial: 1,
externalId: 1,
status: 1
}
}, {
$lookup: {
from: 'device_events',
localField: '_id',
foreignField: 'deviceId',
as: 'join'
}
}
])
옵션 2 변환의 DeviceID String
에 ObjectId
의 device_events 모음
db.device_events.aggerate([
{
$project: {
"deviceObjId": {
"$toObjectId": "$deviceId"
},
_id: 0,
type: 1
}
}, {
$lookup: {
from: 'device',
localField: 'deviceObjId',
foreignField: '_id',
as: 'join'
}
}
])
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다