Answer the question
In order to leave comments, you need to log in
How to export database from MongoDB to JSON file?
SUBJECT!
Here's how I do it:
string connectionString = "mongodb://localhost:27017";
MongoClient client = new MongoClient(connectionString);
IMongoDatabase database = client.GetDatabase("mybase");
IMongoCollection<User> collection = database.GetCollection<User>("Users");
StreamWriter sr = new StreamWriter("JSON.txt");
var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
sr.Write(collection.ToJson(jsonWriterSettings));
sr.Close();
MessageBox.Show("ГОТОВО");
{ "_t" : "MongoCollectionImpl`1" }
Answer the question
In order to leave comments, you need to log in
the mongo package includes an export utility , everything is very simple:
mongoexport --db test --collection traffic --out traffic.json
You need to loop through the collection and write to the file in the loop.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question