[MongoDB] BSONError: cyclic dependency detected 오류 해결 과정

Woong·2023년 3월 17일
0

DB

목록 보기
15/16
  • 순환 참조 오류라고 하지만, 순환 참조로 보이지 않는 쿼리였다.
db.ex_main.find({ _id: { 
  $nin: 
    db.ex_details.find({ category: 'type', ref_id: { $exists: true } })
      .map(function(doc) { return doc.ref_id; })
}})
  • 원인 : 1차로 파이프라인에서 가져온 cursor 를 다른 파이프라인으로 넘겼기 때문이었다.

  • 해결 : toArray() 로 배열로 캐스팅하여 문제 해결

db.ex_main.find({ _id: { 
  $nin: 
    db.ex_details.find({ category: 'type', ref_id: { $exists: true } })
      .map(function(doc) { return doc.ref_id; })
      .toArray()
}})

reference

0개의 댓글