How to export JSON from MongoDB using Robomongo

前端 未结 14 1037
暗喜
暗喜 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

提交回复
热议问题