0

To export your mongodb, you can using mongoexport command, but previously you should install the mongodb-clients:

sudo apt install mongodb-clients

mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance.

mongodb data example:

{
    "_id" : ObjectId("5d3fd4d842fefba971a39b64"),
    "data" : {
        "CATEGORIES_LIST" : [ 
            "Fashion", 
            "Fashion Wanita", 
            "Tas Wanita"
        ],
        "STOCK" : "available",
        "PRICE" : 92000.0,
        "COLORS" : [ 
            "COKELAT MUDA"
        ],
        "PRICE_ORIGINAL" : 92000.0,
        "NAME" : "POBA TAS P11",
        "URL" : "https://www.klikindomaret.com/product/p11-tas-cokelat-muda-all-size",
        "SIZES" : [ 
            "ALL SIZE"
        ],
        "SLUG" : "/product/p11-tas-cokelat-muda-all-size",
        "CATEGORIES_STRING" : "Fashion, Fashion Wanita, Tas Wanita",
        "DISCOUNT" : null
    },
    "model" : "product"
}

With authentication:

mongoexport --host=<host> --port=<port> \
            --username=<username> --password=<password> \
            --db=<database_name> --collection=<collection> \
            --type=<type> \
            --fields=<field_names> \
            --out=<out_file>


# example

mongoexport --host=yourdomain.com --port=27017 \
            --username=yourusername --password=yourpassword \
            --db=yourdatabase --collection= \
            --type=csv \
            --fields="data.NAME,data.PRICE,data.PRICE_ORIGINAL,data.DISCOUNT,data.STOCK,data.CATEGORIES_STRING,data.SIZES,data.URL" \
            --out=klikindomaret.csv

yourcollection

Without authentication:

mongoexport --db=<database_name> --collection=<collection> --type=<type> --fields=<field_names> --out=<out_File>


mongoexport --db=yourdatabase --collection=yourcollection --type=csv --fields="data.NAME,data.PRICE" --out=klikindomaret.csv
mongodb bash database

Your Answer

blog comments powered by Disqus