1
    "it is showing error like :- JSON reader was expecting a value but 
    found 'mongodump'.'"

    //i tried this code but itr=s not working 
    "var cmd = new JsonCommand<BsonDocument>(" mongodump--db XEAP --out 
    F:\\");
    database.RunCommand(cmd);"

I want to take backup of database using c# code.

   "var cmd = new JsonCommand<BsonDocument>(" mongodump--db XEAP --out 
    F:\\");
    database.RunCommand(cmd);"
Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31
Nivrutti
  • 51
  • 6
  • 2
    Possible duplicate of [Run MongoDump / MongoRestore in C#](https://stackoverflow.com/questions/16716407/run-mongodump-mongorestore-in-c-sharp) – Maksim Simkin Jun 14 '19 at 11:52
  • but, there i didn't get any appropriate solution for my question, if you have any solution please help .. – Nivrutti Jun 14 '19 at 11:57

1 Answers1

2

database.RunCommand executes MongoDB command.

mongodump is an OS-level executable. This thread explains how to run this kind of command from C#. Run Command Prompt Commands

Anton
  • 3,587
  • 2
  • 12
  • 27
  • Tanks for reply, but i don't want to create new process i just want to execute that command within current program – Nivrutti Jun 17 '19 at 04:36
  • I don't think MongoDB would let you do that. For C# you can use WaitForExit(); https://stackoverflow.com/questions/15676058/how-to-execute-a-command-via-command-line-and-wait-for-it-to-be-done so you program waits for backup to complete, before doing anything else. – Anton Jun 17 '19 at 13:00