I want to run below mongo query from C#. Currently I am using mongodb C# driver 2.7
db.changelog.find({}).forEach(function(doc){
//make javascript object dynimacally
var newDoc = {
"key": "value",
"doc": doc
}
db.changelog_log.insertOne(newDoc); })
This is successfully run into mongo shell, now I want to execute that script from c# application with modify object value dynamically. I was hoping it would be able to parse those queries and pass them off to database.RunCommand but I have not been able to make any progress.
var bsonDoc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>("query");
database.RunCommand(command);
That code fails on the call to Deserialize with this error message: [Additional information: JSON reader was expecting a value but found 'db'.] which makes perfect sense because the script is not valid JSON.
After mongo 3.0 eval function has been depreciated.
So I'm having trouble parsing the script into something that can be executed.