-->

DEVOPSZONES

  • Recent blogs

    How to COPY or CLONE MongoDB Databases

    How to COPY or CLONE MongoDB Databases


    db.copyDatabase  :- > The "db.copyDatabase" method is used to copy a database either from one mongod instance to the current mongod instance or within the same mongod instance. 

    Syntax:

    db.copyDatabase(fromdb, todb, fromhost, username, password, mechanism)

    Options:

    fromdb : - > Name of the source database.
    todb : -> Name of the target database.
    fromhost : -> The hostname of the source mongod instance. Omit to copy databases within the same mongod instance.
    username : -> The name of the user on the fromhost MongoDB instance. The user authenticates to the fromdb.



    1. Here are databases . 

    > show dbs;
    admin      0.000GB
    config     0.000GB
    dev_XXX   0.000GB
    local      0.000GB
    prod_XXX  0.000GB
    testing    0.000GB
    >
    >

    2. Coping Database testing to testing-copy.

    > db.copyDatabase("testing","testing-copy");
    WARNING: db.copyDatabase is deprecated. See http://dochub.mongodb.org/core/copydb-clone-deprecation
    {
            "note" : "Support for the copydb command has been deprecated. See http://dochub.mongodb.org/core/copydb-clone-deprecation",
            "ok" : 1
    }
    >
    mngodb copy


    3. Check copied Database.


    show dbs;
    admin         0.000GB
    config        0.000GB
    dev_XXX      0.000GB
    local         0.000GB
    prod_XXX     0.000GB
    testing       0.000GB
    testing-copy  0.000GB
    >


    4. Check the collections within the newly copied database :

    > use testing-copy;
    switched to db testing-copy
    > show collections;
    users
    >
    mongodb collections

    No comments