How to export JSON from MongoDB using Robomongo

前端 未结 14 763
暗喜
暗喜 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 01:58

    Using a robomongo shell script:

    //on the same db
    var cursor = db.collectionname.find();
    
    while (cursor.hasNext()) {
        var record = cursor.next();   
        db.new_collectionname.save(record);
    }
    

    Using mongodb's export and import command

    You can add the --jsonArray parameter / flag to your mongoexport command, this exports the result as single json array.

    Then just specify the --jsonArray flag again when importing.

    Or remove the starting and ending array brackets [] in the file, then your modified & exported file will import with the mongoimport command without the --jsonArray flag.

    More on Export here: https://docs.mongodb.org/manual/reference/program/mongoexport/#cmdoption--jsonArray

    Import here: https://docs.mongodb.org/manual/reference/program/mongoimport/#cmdoption--jsonArray

    0 讨论(0)
  • 2021-01-30 01:59

    If you want to use mongoimport, you'll want to export this way:

    db.getCollection('tables')
      .find({_id: 'q3hrnnoKu2mnCL7kE'})
      .forEach(function(x){printjsononeline(x)});
    
    0 讨论(0)
  • 2021-01-30 02:00

    Don't run this command on shell, enter this script at a command prompt with your database name, collection name, and file name, all replacing the placeholders..

    mongoexport --db (Database name) --collection (Collection Name) --out (File name).json
    

    It works for me.

    0 讨论(0)
  • 2021-01-30 02:01

    A Quick and dirty way: Just write your query as db.getCollection('collection').find({}).toArray() and right click Copy JSON. Paste the data in the editor of your choice.

    0 讨论(0)
  • 2021-01-30 02:01

    Solution:

    mongoexport --db test --collection traffic --out traffic.json<br><br>
    

    Where:
    database -> mock-server
    collection name -> api_defs
    output file name -> childChoreRequest.json

    0 讨论(0)
  • 2021-01-30 02:01
    1. make your search
    2. push button view results in JSON mode
    3. copy te result to word
    4. print the result from word
    0 讨论(0)
提交回复
热议问题