How to export JSON from MongoDB using Robomongo

前端 未结 14 762
暗喜
暗喜 2021-01-30 01:37

So I do not know much about MongoDB. I have RoboMongo using which I connect to a MongoDB. What I need to do is this - there is a collection in that Mon

相关标签:
14条回答
  • 2021-01-30 02:02

    I don't think robomongo have such a feature. So you better use mongodb function as mongoexport for a specific Collection.

    http://docs.mongodb.org/manual/reference/program/mongoexport/#export-in-json-format

    But if you are looking for a backup solution is better to use

    mongodump / mongorestore
    
    0 讨论(0)
  • 2021-01-30 02:05

    I had this same issue, and running script in robomongo (Robo 3T 1.1.1) also doesn't allow to copy values and there was no export option either. The best way I could achieve this is to use mongoexport, if mongodb is installed on your local, you can use mongoexport to connect to database on any server and extract data

    To connect to Data on remote server, and csv output file, run the following mongoexport in your command line

    mongoexport --host HOSTNAME --port PORT --username USERNAME --password "PASSWORD" --collection COLLECTION_NAME --db DATABASE_NAME --out OUTPUTFILE.csv --type=csv --fieldFile fields.txt
    

    fieldFile: helps to extract the desired columns, ex: contents of fields.txt can be just:

    userId

    to only extract values of the column 'userId'

    Data on remote server, json output file:

    mongoexport --host HOST_NAME --port PORT --username USERNAME --password "PASSWORD" --collection COLECTION_NAME --db DATABASE_NAME --out OUTPUT.json
    

    this extracts all fields into the json file

    data on localhost (mongodb should be running on localhost)

    mongoexport --db DATABASE_NAME --collection COLLECTION --out OUTPUT.json
    

    Reference: https://docs.mongodb.com/manual/reference/program/mongoexport/#use

    0 讨论(0)
提交回复
热议问题