Sample Header Ad - 728x90

Copy Specific Columns from DB 1 To DB 2 on MongoDB

1 vote
2 answers
2168 views
I have Two Instance of Node JS server which is handled By NGINX. First server is connect with MongoDB First Server i.e > mongoose.connect('mongodb://127.0.0.1/db_primary', { useMongoClient: true }); While Second Node Js Server is Connect with MongoDB Second Serer i.e > mongoose.connect('mongodb://127.0.0.1/db_secondary', { useMongoClient: true }); Actually, I have to Do some Heavy Calculations on DB and that the main reason I will divide my DB into Two Pieces. Initially When I have One Server then if the backend is busy with calculations (Millions of Entries) at that time Server is completely freeze. So by the Separation There is now no freezing point of server. My Question is How I can Copy the selected Columns on The entire Table form DB 1 And paste it to DB 2 with only Selected Columns. Example:Database 1 { _id: ObjectID(54815dfsfsd1f564168ad51a5s), a: 123, b: 768, c: 89.67, d: 8976, e: 45 }..........upto 10 million entries Now I want to Copy Only Column c & e from Database 1 to Database 2. Expected Result: { _id: ObjectID(54815dfsfsd1f564168ad51a5s), c: 89.67, e: 45 }..........upto 10 million entries And all these things are done by CronJob of Nodejs. I mean Not a manual task. I am Newbie on MongoDB. Any help is appreciated.
Asked by Ankit (121 rep)
Jan 29, 2018, 06:54 AM
Last activity: Jul 29, 2025, 12:03 PM