이 모음에 따라 필드의 값을 찾아, 나는 다음과 같은 두 개의 컬렉션이 있습니다 각각에 대해MongoDB를 : 나는 MongoDB를 사용하고
{
name:"Paris",
country:"FR",
population:8022,
location:{
longitude:42.46372,
latitude:1.49129
}
}
:
담당자 :
{
"name":"Bob",
"info":{
"birthplace":[
"Paris, France"
],
"birthdate":[
"18 June 1961"
]
}
}
시 출생지가 알려진 사람, 그 도시의 위치와 인구를 찾고 싶습니다. 나는 문서를 보면서 우리는 다음과 같이 집계 $lookup
를 사용할 수있는 것을 발견 :
Person.orders.aggregate([
{
$lookup:
{
from: "City",
localField: "birthplace",
foreignField: "name",
as: "inventory_docs"
}
}
])
을 그러나 문제는 City.name
의 값이 Person.birthplace
에 포함되어 있다는 것입니다, 그래서 그들은 일치하지 않을 수 있습니다, 어떤 아이디어? 감사!