How to export JSON from MongoDB using Robomongo

前端 未结 14 1036
暗喜
暗喜 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:43

    You can use tojson to convert each record to JSON in a MongoDB shell script.

    Run this script in RoboMongo:

    var cursor = db.getCollection('foo').find({}, {});
    while(cursor.hasNext()) {
        print(tojson(cursor.next()))
    }
    

    This prints all results as a JSON-like array.

    The result is not really JSON! Some types, such as dates and object IDs, are printed as JavaScript function calls, e.g., ISODate("2016-03-03T12:15:49.996Z").

    Might not be very efficient for large result sets, but you can limit the query. Alternatively, you can use mongoexport.

提交回复
热议问题