I have added the following function in my Mongo database:
db.system.js.save({
_id: "testFunction",
value: function (int) {
return int;
}
})
I'm using the following packages in my C# project:
mongocsharpdriver 2.14.1 MongoDB.Driver 2.14.1
The function runs with no issue in a Mongo shell.
Is there a way to run it in a C# code? I have searched for a solution for a few hours but with no luck.
Please note that the Eval method/option is not available in above driver version, so please don't suggest it.
In addition, I'm aware of the CommandDocument class but couldn't figure out how to create it for calling the above function.
Thanks in advance !
I am also looking for the same but didn't find anything relevant so i decided to go with aggrgate() function in c# and suggesting to you also if you are not performing much complex queries in MongoDB function. The aggregate functions can also accept json format as MongoDB queries so you can try that something like this.
database.GetCollection<BsonDocument>("collection").Aggregate()
.Lookup("ForeignCollection", "LocalName", "ForeignName", "Object").Match("AnyFilter").Project(Builders<BsonDocument>.Projection.Exclude("field1").Include("field2")).ToList();