2016-08-30 3 views
4

나는 이런 식으로 뭔가를 할 노력하고있어 :

use user; 

db.user.aggregate([ 
    { 
     $lookup: 
     { 
      from: "organization.organization", 
      localField: "organizationId", 
      foreignField: "uuid", 
      as: "user_org" 
     } 
    } 
]) 

userorganization 두 개의 서로 다른 데이터베이스에 있습니다.

이것이 가능하지 않은 경우 대체 방법은 무엇입니까?

답변

4

는 MongoDB를 두 데이터베이스 사이에 $ 조회 집계를 할 수 있습니까?

두 개의 다른 db에서 조회를 사용하여 쿼리 할 수 ​​없습니다. $lookup in mongodb supports 동일한 데이터베이스의 공유되지 않은 모음에 대해 왼쪽 외부 조인을 수행합니다. MongoDB cross database query

+1

확인 오 -

{ $lookup: { from: <collection to join>, localField: <field from the input documents>, foreignField: <field from the documents of the "from" collection>, as: <output array field> } } 

우리는

db.getSiblingDB('test').foo.find() 

참조 일dB에서 다른 DB를 조회 할 수 getSibling("dbname")를 사용할 수 있습니다. 하지만 어떻게 형제 DB를 사용합니까? 심지어 가능할까요? –

+0

형제는 집계 할 수 없습니다. –