본문 바로가기

sw사관학교정글

mongoDB merge

반응형

몽고디비 마지를 해야하는데

자꾸 join방법만 나와서 한참을 헤매다가

 

https://stackoverflow.com/questions/26346216/merge-two-collections-on-mongodb

 

Merge two collections on mongodb

I need to merge two collections into one, but I need to put the document only if it doesn't exists in the first collection. How can I do it? What's the best way? I saw something about agregation and

stackoverflow.com

이 글을 발견했다

 

하나씩 다 넣는거라 시간이 오래걸리지만 그래도 해결해서 기쁘다^_^

진짜 이방법 밖에 없는걸까

 

db.collection1.find().forEach(function(item) {
    db.collection2.insert(item);
});

나는 일단 remove는 필요없어서 안씀

반응형

'sw사관학교정글' 카테고리의 다른 글

Javascript 비동기 처리  (0) 2021.12.10
JavaScript 추상클래스  (0) 2021.12.07
aws cpu 100%일 때 - swap 메모리  (0) 2021.12.04
mongoDB 모델링 방법  (0) 2021.11.12
쿠키 세션 JWT  (0) 2021.11.11