-
Type: Task
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.7.0
-
Component/s: Command Operations, Feature Request
I want to run mongo find query with foreach operation directly on mongo server because through foreach operation I want to insert documents into other collection with extra properties. My mongo query is below
db.products.find({}).forEach(function(doc){ //make javascript object dynimacally var newDoc = { "user_name": "name", "user_action": "insert|update", "doc": doc } db.logCollection.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.
So I'm having trouble parsing the script into something that can be executed.