Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

311
Vistas
Move a collection from one DB to another DB within the same MongoDB instance

I have many collections in database A. I want to copy some of them to database B in the same MongoDB.

I tried to copy whole database using db.copyDatabase('A', 'B'), but it has more than 300 GB data. It will take ages to copy and I just want to copy a few collections from database A to database B.

Does anyone know how can I do it?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can try it using mongo shell. you can copy collection from one db to another db using renameCollection. the renameCollection can run from admin database so first need to switch to admin db.

so ca follow bellow steps in mongo shell:

step-1: run this comment use admin

step-2: run bellow comment

db.runCommand({renameCollection:"sourcedb.sourceCollection",to:"targetdb.tragetCollection"})

for example:

use admin
db.runCommand({renameCollection:"funnel.countries",to:"test.countries"})

copied countries collection from funnel db to test db.

In background MongoDB will create dump for source collection and restore the dump automatically to target db collection

over 4 years ago · Santiago Trujillo Denunciar

0

Use mongodump to dump the collections:

mongodump  --db A --collection coll --out yourbackupdir

and then import the collections using mongorestore:

mongorestore --db B --collection coll yourbackupdir/
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda