Call MongoDB Stored Javascript Function in C# .Net(在 C# .Net 中调用 MongoDB 存储的 Javascript 函数)
问题描述
我需要在 C# 代码中调用 MongoDB 存储的 JavaScript 函数.
I need to call a MongoDB Stored JavaScript Function in C# Code.
我存储的 JavaScript 函数 GetUserInfo
My Stored JavaScript Function GetUserInfo
function() {
return db.getCollection('Profession').find({});
}
执行:
db.loadServerScripts();
GetUserInfo();
它返回带有以下文档的集合(这里我只粘贴了 2 个文档,实际上我有超过 10K 个文档)
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"
}
在 C# 中:
IMongoClient _client;
IMongoDatabase _database;
_client = new MongoClient();
_database = _client.GetDatabase("SampleDB");
请帮助我如何在 C# 代码中调用 MongoDB 存储的 JavaScript 函数.
Kindly assist me how to call MongoDB Stored JavaScript Function in C# Code.
以下问题使用 Eval
.在最新的驱动中,我找不到扩展函数_database.Eval
The following Question uses Eval
. In the latest driver, I can't able to find the Extended Function _database.Eval
通过 C# 调用 MongoDB 中的存储过程
请帮助我...
推荐答案
您可以使用 RunCommand 方法 执行 eval 命令.我们已将其从 API 本身中删除,因为我们不希望您使用它.查看这些部分,了解为什么不应该使用 eval,第一个和第二个.
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.
我强烈建议您重新考虑您的存储过程"策略.虽然我赞赏您为集中和 DRY 代码所做的努力,但 MongoDB 中的 eval 会降低性能和并发性.
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.
这篇关于在 C# .Net 中调用 MongoDB 存储的 Javascript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# .Net 中调用 MongoDB 存储的 Javascript 函数


基础教程推荐
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01
- 创建属性设置器委托 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01