从Azure函数连接到MongoDB [英] Connecting to MongoDB from azure function
问题描述
我从在Microsoft Azure上运行的C#函数连接到MongoDB时遇到问题.该函数是时间触发的,它应该从MongoDB收集一些数据并将其放入存储队列.
I have a problem connecting to a MongoDB from a C# function running on microsoft azure. The function is time triggered, it should collect some data from MongoDB and put them to storage queue.
我已经将mongoDB依赖项添加到project.json中,这就是文件的样子:
I have added mongoDB dependencies to the to project.json and this is what the file looks like:
{
"frameworks": {
"net46":{
"dependencies": {
"MongoDB.Bson": "2.4.2",
"MongoDB.Driver": "2.4.2",
"MongoDB.Driver.Core": "2.4.2",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
}
}
}
}
但是,当我打电话给我时:
However when i call:
MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(conn));
settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
var client = new MongoClient(settings);
调用最后一行后出现错误:
I get an error after the last line is called:
mscorlib: Exception has been thrown by the target of an invocation. MongoDB.Driver.Core: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
我已经检查过,并且.net版本是4.6,所以应该没有问题.还有其他我想念的吗?
I've checked and .net version is 4.6 so there should be no problem with that. Is there anything else I am missing.
推荐答案
I've been digging a bit through their JIRA issues and found JIRA ISSUE. I've reverted the MongoDB.Driver
MongoDB.Driver.Core
and MongoDB.Bson
to a version 2.3.0 and it work like a fine tuned watch, so it seems to be the problem with the Mongo package itself.
我已经使用不同版本的软件包对其进行了测试,并且此问题在2.4.0版本中引入.所有以前的版本都运行良好.
I've tested it with the different versions of the package and the issue is introduced in the version 2.4.0. All the previous versions work well.
这篇关于从Azure函数连接到MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!