小编Jaa*_*aap的帖子

你能在Mongo中为$ addToSet指定一个键吗?

我有一份文件:

{ 'profile_set' :
  [
    { 'name' : 'nick', 'options' : 0 },
    { 'name' : 'joe',  'options' : 2 },
    { 'name' : 'burt', 'options' : 1 }
  ] 
}
Run Code Online (Sandbox Code Playgroud)

并且如果名称尚不存在(无论选项如何),都希望将新文档添加到profile_set集.

所以在这个例子中,如果我试图添加:

{'name' : 'matt', 'options' : 0}

它应该添加它,但添加

{'name' : 'nick', 'options' : 2}

应该什么也不做,因为文件已经存在,nick即使名称option不同.

Mongo似乎与整个元素匹配,我最终检查它是否相同,我最终得到了

profile_set containing [{'name' : 'nick', 'options' : 0}, {'name' : 'nick', 'options' : 2}]
Run Code Online (Sandbox Code Playgroud)

有没有办法用$ addToSet执行此操作,还是我必须推送另一个命令?

mongodb pymongo

64
推荐指数
2
解决办法
2万
查看次数

Visual Studio代码:禁用引用包装文本选择

当我想从双引号更改为单引号时,我习惯选择双引号,然后键入单引号.我打算使用覆盖功能,但相反,我正在使用'wrap with quote'功能.

例如:

"id"
Run Code Online (Sandbox Code Playgroud)

会导致:

'"'id"
Run Code Online (Sandbox Code Playgroud)

我总是将这个自动环绕声关闭,但我无法在设置文件中找到此设置...

有没有办法把它关掉?

visual-studio-code vscode-settings

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

Scala宏:typed(又名typechecked)和无类型树之间有什么区别

我开始使用scala宏,它们很棒,但我遇到了typed(又是typechecked)和无类型Trees 之间的区别.

例如,c.eval由于某种原因,您无法使用类型检查的树进行调用.我在scala宏文档中找不到关于这个'typechecked'的文档(我知道他们仍然在努力,这可能是某些事情需要在某天添加).

对于一个Tree被类型检查来说意味着什么?为什么它们如此不同以至于显然c.eval无法处理类型检测Tree(反之则对我更有意义).

我想这可能是编译器101,但我没有采取这个过程:(任何解释或指向文章/文件的指针将不胜感激!

scala typechecking scala-macros

15
推荐指数
1
解决办法
1428
查看次数

啤酒升级后用俄语git cli

在升级后,我的git cli切换到俄语.我试图找到原因,或者如何,但没有任何线索.

$ git --version
git version 2.19.0
Run Code Online (Sandbox Code Playgroud)

我该如何解决!?

我的语言环境根本没有提到俄语

$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
Run Code Online (Sandbox Code Playgroud)

git command-line-interface

11
推荐指数
1
解决办法
1144
查看次数

ASP.NET MVC 3自定义RouteBase和OutputCache

我的自定义RouteBase实现有问题[OutputCache].我们有一个CMS,其中URL被映射到某些内容页面.每种类型的内容页面由不同的控制器(和不同的视图)处理.网址是完全免费的,我们需要不同的控制器,因此"catchall"路由不可用.因此,我们构建了一个自定义RouteBase实现,该实现调用数据库来查找所有URL.数据库知道要使用哪个Controller和Action(基于内容页面类型).

这很有用.

但是,将此与[OutputCache]属性相结合,输出缓存不起作用(页面仍然有效).我们确保[OutputCache]适用于我们的"普通"路由.

调试输出缓存是非常困难的,属性就在那里,我们就是它,它不起作用......想法如何处理这个将是非常受欢迎的,正确的答案也是如此!

控制器看起来像这样:

public class TextPageController : BaseController
{
  private readonly ITextPageController textPageController;

  public TextPageController(ITextPageController textPageController)
  {
    this.textPageController = textPageController;
  }

  [OutputCache(Duration = 300)]
  public ActionResult TextPage(string pageid)
  {
    var model = textPageController.GetPage(pageid);
    return View(model);
  }
}
Run Code Online (Sandbox Code Playgroud)

自定义路线如下所示:

public class CmsPageRoute : RouteBase
{
  private IRouteService _routeService;
  private Dictionary<string, RouteData> _urlsToRouteData;

  public CmsPageRoute(IRouteService routeService)
  {
    this._routeService = routeService;
    this.SetCmsRoutes();
  }

  public void SetCmsRoutes()
  {
    var urlsToRouteData = new Dictionary<string, RouteData>();
    foreach (var route in …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc outputcache asp.net-mvc-routing

10
推荐指数
1
解决办法
2346
查看次数

Mockito scala验证测试不起作用(播放框架)

我正在尝试使用Scala中的Play框架进行单元测试.我写了一个类来检查配置是否正确(我有更多的错误处理,但我实际上现在使用此代码进行测试):

class TaskQueueConfig(conf: Configuration) {
  val schedulingEnabled = conf.getBoolean("schedulingEnabled").get
  val processingEnabled = conf.getBoolean("processingEnabled").get
  val queueName = conf.getString("queue").get
}
Run Code Online (Sandbox Code Playgroud)

我正在使用play 2.1.1的默认测试设置来测试它:

class ConfigTestSpec extends Specification with Mockito with CalledMatchers {
  "TaskQueueConfig" should {
     "verify calls" in {
      val tqConf = mock[Configuration]
      tqConf.getString("queue") returns Some("queueName")
      tqConf.getBoolean("schedulingEnabled") returns Some(true)
      tqConf.getBoolean("processingEnabled") returns Some(true)
      Logger.error("setup done")

      val config = new TaskQueueConfig(tqConf)

      there was one(tqConf).getString("queue")
      there were two(tqConf).getBoolean(any[String])
      there were one(tqConf).getBoolean("schedulingEnabled")
      there were one(tqConf).getBoolean("processingEnabled")
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

[error] x verify calls
[error]    The mock was …
Run Code Online (Sandbox Code Playgroud)

scala mockito playframework

8
推荐指数
1
解决办法
2382
查看次数

jQuery删除(选择器)似乎不起作用

我创建了一个小jsfiddle:http: //jsfiddle.net/duRXc/

<div data-role="wrapper">
    <span class="to-be-removed" data-role="to-be-removed">
        text to be removed
    </span>
</div>
<button id="remove1">Remove by jQuery object</button><br>
<button id="remove2">Remove by selector</button><br>
<button id="remove3">Remove by selector(class)</button>

var $wrapper = $('[data-role="wrapper"]');

$('#remove1').on('click', function () {
    $wrapper.find('[data-role="to-be-removed"]').remove();
});

// this should work: http://api.jquery.com/remove/
$('#remove2').on('click', function () {
    $wrapper.remove('[data-role="to-be-removed"]');
});

// this should work: http://api.jquery.com/remove/
$('#remove3').on('click', function () {
    $wrapper.remove('.to-be-removed');
});
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是.remove(选择器)重载不起作用.我认为它与我的数据角色选择器有关,但是按类选择器的删除也不起作用.

难道我做错了什么?或者这是jQuery中的错误还是文档错误:

我们还可以包含一个选择器作为可选参数

http://api.jquery.com/remove/

jquery

7
推荐指数
1
解决办法
4344
查看次数

检测谷歌计算实例启动脚本完成了吗?

在 Google Compute Engine 中,启动虚拟机时会创建一个操作。操作完成后,虚拟机已准备就绪(否则操作可能处于失败状态)。但是,我的启动脚本(通过 指定startup-script-url)在成功插入操作后仍在运行。

有没有办法使用compute api进行检测?

我使用的是googleapis节点库,它基本上是官方计算 Api 的包装器(https://developers.google.com/apis-explorer/#p/compute/v1/)。

当我手动执行此操作时,我只关注串行控制台。

startupscript google-compute-engine

7
推荐指数
1
解决办法
2065
查看次数

Oracle(PL/SQL):UPDATE RETURNING并发吗?

我正在使用带有计数器的表来确保子元素上的唯一id.

我知道使用序列通常更好,但我不能使用它,因为我有很多计数器(客户可以创建几个桶,每个都需要有自己的计数器,他们必须从1(这是一项要求,我的客户需要"人类可读的"键).

我正在创建具有prikey的记录(让我们称之为项目)(bucket_id,num = counter).

我需要保证bucket_id/num组合是唯一的(因此使用序列作为prikey不会解决我的问题).

在pl/sql中不会发生行的创建,因此我需要声明数字(顺便说一下:它不符合要求有间隙).

我的解决方案是:

   UPDATE bucket
      SET counter = counter + 1
    WHERE id = param_id
RETURNING counter INTO num_forprikey;
Run Code Online (Sandbox Code Playgroud)

PL/SQL返回var_num_forprikey,因此可以创建项记录.

题:

即使用户同时要求存储桶中的新项目,我是否总能获得唯一的num_forprikey?

oracle concurrency plsql

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

Play Framework [2.2-scala]:从缓慢的InputStream创建Enumerator

我正在实施AWS S3文件传递API.我被迫将S3的S3ObjectInputStream中的字节流式传输到浏览器.我们有一个用例用云端服务文件不是一个选项(主要是本地开发)

我有一个InputStream,所以最明显的事情是使用带有Enumerator.fromStream()的Ok.chunked,但Enumerator.fromStream()有一个非常明确的警告,即流不应该很慢.我假设AWS S3ObjectInputStream可能是最慢的流之一.

http://www.playframework.com/documentation/2.2.x/api/scala/index.html#play.api.libs.iteratee.Enumerator$

def fromStream(input: InputStream, chunkSize: Int = 1024 * 8)
              (implicit ec: ExecutionContext): Enumerator[Array[Byte]]

Create an enumerator from the given input stream.

This enumerator will block on reading the input stream, in the default iteratee
thread pool. Care must therefore be taken to ensure that this isn't a 
slow stream. If using this with slow input streams, consider setting the value
of iteratee-threadpool-size to a value appropriate for handling the blocking.
Run Code Online (Sandbox Code Playgroud)

所以我想知道最安全的方法是避免线程饥饿并将文件流式传输到浏览器而不将整个文件保存在内存中.

是否有其他方法可以从InputStream获取枚举器(或我们可以在结果中发送的内容)?

inputstream enumerator playframework

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