小编Ale*_*llo的帖子

MongoDB C#Driver 2.0 - 更新文档

我目前正在将我的代码升级到MongoDB C#驱动程序2.0,并且我在升级代码以更新文档时遇到问题.

使用旧版本,我能够做到这样的事情:

MyType myObject; // passed in 
var collection = _database.GetCollection<MyType>("myTypes");
var result = collection.Save(myObject);
Run Code Online (Sandbox Code Playgroud)

我很难在新版本中找到一种方法.我找到了一些更新单个字段的例子

var filter = Builders<MyType>.Filter.Eq(s => s.Id, id);
var update = Builders<MyType>.Update.Set(s => s.Description, description);
var result = await collection.UpdateOneAsync(filter, update);
Run Code Online (Sandbox Code Playgroud)

我想用旧方法更新所有字段,方法是Save.

有任何想法吗 ?

非常感谢

c# mongodb mongodb-csharp-2.0 mongodb-.net-driver

29
推荐指数
3
解决办法
4万
查看次数

.Net Core中的UseUnsafeHeaderParsing设置

我曾经在完整的.Net框架中使用此设置来处理我正在联系的服务器返回的一些不安全的标头.

 <system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
 <system.net>
Run Code Online (Sandbox Code Playgroud)

我真的找不到在.Net核心中做同样事情的方法.(控制台应用)

有帮助吗?

system.net httpclient .net-core

13
推荐指数
1
解决办法
559
查看次数

Azure git部署失败

我从bitbucket部署了几个azure web应用程序.这一切都很好,从来没有任何问题.自上次提交以来,azure部署现在失败,并出现以下错误:

Command: deploy.cmd

Installing Kudu Sync

D:\local\AppData\npm\kudusync -> D:\local\AppData\npm\node_modules\kudusync\bin\kudusync

kudusync@0.2.3 D:\local\AppData\npm\node_modules\kudusync

??? commander@2.6.0

??? q@1.1.2

??? minimatch@2.0.1 (brace-expansion@1.1.0)

Test

'D:\Program' is not recognized as an internal or external command,

Handling .NET Web Application deployment.

operable program or batch file.

An error has occured during web site deployment.
Run Code Online (Sandbox Code Playgroud)

通常当代码导致部署错误时,我可以通过检查错误来找到根本原因,但这次似乎完全不相关.

以前有人有类似的问题吗?

谢谢

git deployment bitbucket azure azure-deployment

4
推荐指数
1
解决办法
897
查看次数

在Ubuntu/Visual Studio代码上从.Net Core连接到SqlServer

我有一个连接到SQL Server数据库的控制台应用程序(托管在同一网络中的专用win机器上),用.Net核心编写(使用Visual Studio Code),它在Windows上工作得非常好.

在Ubuntu上的Visual Studio代码上运行的相同代码库无法连接到SQL Server实例,说它无法找到服务器.

我可以ping SQL Server IP并从中获取响应.

此外,我可以使用1433端口上的telnet连接到SQLServer实例.

另外,我已按照建议从nuget中提取System.Data.Common和System.Data.SqlClient,并按照建议在连接字符串中设置MultipleActiveResultSets = False.

为了完整性,这是尝试连接的代码:

var connection = new SqlConnection(myConnectionString);
connection.Open();
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪:

Unhandled Exception: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.AggregateException: One or …
Run Code Online (Sandbox Code Playgroud)

sql-server ubuntu .net-core visual-studio-code

4
推荐指数
1
解决办法
2114
查看次数

C#MongoDB驱动程序2.0-从近距离查询返回距离

我正在使用C#MongoDB驱动程序2.0进行NearSphere查询,并且工作正常。结果是按距离自动排序的,但是我希望为每个搜索结果找回该距离,以便能够将其显示回来。我发现这篇文章说如何针对旧版本的驱动程序执行此操作,并从Near查询中检索距离“ dis”结果,但未设法找到如何使用新驱动程序进行操作。

这是我的代码:

var collection = database.GetCollection<MyType>("myTypes");
var locFilter = Builders<MyType>.Filter.NearSphere(x => x.GeoLocation, criteria.Long, criteria.Lat, criteria.RadiusInMiles/3963.2);
var results = await collection.Find(locFilter).ToListAsync();
Run Code Online (Sandbox Code Playgroud)

我想我必须在IFindFluent结果上调用ToList之前做点什么?

有什么帮助吗?

非常感谢

c# location distance geolocation mongodb

3
推荐指数
1
解决办法
1647
查看次数