sw사관학교정글

mongoDB merge

29도 맑음 2022. 4. 5. 23:13
반응형

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

자꾸 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는 필요없어서 안씀

반응형