小编Gui*_*ira的帖子

IHttpActionResult vs IActionResult

我正在使用.NET Core 2创建一个API,为不同技术开发的许多应用程序提供数据.我正在IActionresult从我的方法回来.我一直在研究返回数据的最佳选择,并看到一些使用的示例IHttpActionResult.现在我不知道哪种类型最好返回.

IHttpActionResult和之间有什么区别IActionresult

c# rest asp.net-core

12
推荐指数
2
解决办法
5942
查看次数

不使用 $project 将嵌套文档投影到根级别

使用聚合管道,我试图将嵌入的文档投影到根级别,而不单独投影每个字段,也不替换根级别。

例如,我想将此集合投影到根级别:

[
    {
        _id: "1",
        city: "NY"
        user: [ {
            firstName: "John",
            lastname: "Peters",
            brothers: [
                { _id: "B1",
                  brotherFirstName: "Karl" }
            ]
         }, {
            firstName: "Raul",
            lastname: "Other",
            brothers: [
                { _id: "B2",
                  brotherFirstName: "May" }
            ]
         }, {
            firstName: "Paul",
            lastname: "Ray",
            brothers: [
                { _id: "B3",
                  brotherFirstName: "Bryan" }
            ]
         }        
    },
    {
        _id: "2",
        city: "NY"
        user: [ {
            firstName: "Joe",
            lastname: "Anders",
            brothers: [
                { _id: "B4",
                  brotherFirstName: "Carla" }
            ]
         }, {
            firstName: …
Run Code Online (Sandbox Code Playgroud)

javascript mongodb mongodb-query aggregation-framework

6
推荐指数
1
解决办法
1290
查看次数

使用 .NET Core 避免重复 POST

我在 .NET Core REST API 中使用 POST 在数据库中插入数据。

在我的客户端应用程序中,当用户单击一个按钮时,我会禁用该按钮。但有时,由于某种原因,按钮的点击可能比禁用按钮的功能更快。这样,用户可以双击按钮,POST 将被发送两次,插入数据两次。

为了做 POST,我在客户端使用 axios。但是如何在服务器端避免这种情况呢?

.net c# asp.net-core

6
推荐指数
3
解决办法
4983
查看次数

推送到远程Git存储库时遇到错误

我目前正在开发一个托管在visualstudio.com上的项目(Visual Studio online),我选择Git作为代码库,但是当我尝试将代码中的更改推送到Git存储库时,我遇到了错误.

当我使用Visual Studio 2015推送它时,我收到了错误消息:

Error encountered while pushing to the remote repository: Chunked encoding upload is not supported on the HTTP/1.0 protocol
Run Code Online (Sandbox Code Playgroud)

我也在这台机器上安装了Visual Studio 2013,使用VS2013,我可以将更改推送到存储库而不会出现任何错误.

  • 我该怎么做才能解决这个问题?

PS:我在代理服务器后面.(我可以通过代理推送VS2013的更改)

c# git visual-studio visual-studio-2013 visual-studio-2015

5
推荐指数
0
解决办法
2670
查看次数

获取集合和子文档中所有键的名称

我需要从我的集合中获取所有字段名称,包括子文档中的字段.我目前正在运行此命令并仅获取根字段的名称.我如何获得所有字段名称?

我的收藏看起来像这样:

"UserId" : 11111,
"Personal" : {
    "Email" : "email@gmail.com",
    "FirstName" : "Name",
    "LastName" : "Last"
},
"Car" : {
    "CarType" : "NULL"
}
Run Code Online (Sandbox Code Playgroud)

这是命令

var mr = db.runCommand({
"mapreduce" : "myCollection",
  "map" : function() {
    for (var key in this) { emit(key, null); }
  },
  "reduce" : function(key, stuff) { return null; }, 
  "out": "myCollection" + "_keys"
})

db[mr.result].distinct("_id")
Run Code Online (Sandbox Code Playgroud)

我想要这个结果:

UserId,Personal.Email,Personal.FirstName,Personal.LastName,Car.CarType

javascript mongodb mongodb-query aggregation-framework

5
推荐指数
1
解决办法
85
查看次数

从对象数组中获取唯一值

我有一个像这样的动态对象数组:

var arr = [
    {state: "FL"},
    {state: "NY"},
    {state: "FL"},
    {gender: "Male"},
    {state: "NY"},
    {gender: "Female"},
    {gender: "Female"},
    {year: "1990"}
]
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得独特的物体?

所需的输出是一个只包含唯一对象的数组:

arr = [
    {state: "FL"},
    {state: "NY"},
    {gender: "Male"},
    {gender: "Female"},
    {year: "1990"}
]
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用reduce这样的东西,但在这种方式我需要知道对象键:

arr = arr.reduce((acc, curr) => 
    acc.find(e => e['state'] === curr['state']) ? acc : [...acc, curr], [])
Run Code Online (Sandbox Code Playgroud)

这不是重复,因为其他问题不使用"动态对象"来获得独特性

javascript unique

5
推荐指数
1
解决办法
169
查看次数

如果IN子查询没有行,如何返回所有行?

以下是示例查询

Select *
  from tb.Users u
 where u.Approved = 1
   and u.userID IN ( SELECT us.UserID us
                       FROM tb.UserStatementes us
                      WHERE us.LogDate between date1 and date2 )
Run Code Online (Sandbox Code Playgroud)

我需要选择IN子句中的所有用户,但是如果子查询没有返回记录,我需要选择所有用户(即忽略IN子句)

sql t-sql sql-server

0
推荐指数
1
解决办法
82
查看次数