Reputation:
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...
Upvotes: 3
Views: 3405
Reputation: 12624
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.
Upvotes: 1