I need to call a MongoDB Stored JavaScript Function in C# Code.
My Stored JavaScript Function GetUserInfo
function() {
return db.getCollection('Profession').find({});
}
Execution :
db.loadServerScripts();
GetUserInfo();
It returns the Collection with following documents (Here I pasted only 2 Documents, in real I'm having more than 10K Documents)
{
"_id" : ObjectId("575845a713d284da0ac2ee81"),
"Profession_id" : "575841b313d284da0ac2ee7d",
"Prof_Name" : "Chief Officer"
}
{
"_id" : ObjectId("575845d213d284da0ac2ee82"),
"Profession_id" : "575841b313d284da0ac2ee7d",
"Prof_Name" : "Executive Officer"
}
In C#:
IMongoClient _client;
IMongoDatabase _database;
_client = new MongoClient();
_database = _client.GetDatabase("SampleDB");
Kindly assist me how to call MongoDB Stored JavaScript Function in C# Code.
The following Question uses Eval. In the latest driver, I can't able to find the Extended Function _database.Eval
Calling a Stored Procedure in MongoDB via C#
Kindly assist me...
You can use the RunCommand method to execute the eval command. We've removed it from the API itself because we don't want you using it. Have a look at these sections for why you shouldn't be using eval, first and second.
I'd highly suggest you rethink your "stored procedure" strategy. While I applaud your efforts to centralize and DRY your code, eval in MongoDB will kill performance and concurrency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With