Elixir流媒体mongodb失败

时间:2015-01-22 15:44:39

标签: mongodb stream elixir

我正在使用elixir-mongo并尝试流式传输查询结果。这是代码......

def archive_stream(z) do
Stream.resource(
  fn ->
      {jobs, datetime} = z
      lt = datetime_to_bson_utc datetime
      c = jobs |> Mongo.Collection.find( %{updated_at: %{"$lt": lt}}) |> Mongo.Find.exec
      {:cont, c.response.buffer, c}
  end,
  fn(z) ->
    {j, {cont, therest, c}} = next(z)
    case cont do
      :cont -> {j, {cont, therest, c}}
      :halt  -> {:halt, {cont, therest, c}}
    end
  end,
  fn(:halt, resp) -> resp end
)

所有子位似乎都可以工作(就像查询一样),但是当我尝试进入流时,我失败了......

Mdb.archive_stream({jobs, {{2013,11,1},{0,0,0}}})|>Enum.take(2)

我明白了......

  

(BadArityError)#Function< 2.49475906 / 2 in Mdb.archive_stream / 1>使用1参数调用arity 2({:cont,<<<<<<<<<<<<<<<<<<<<< 109,0,137,233,4,95,115,108,117,103,115,0,51,0,0,0,2,48,0,39,0,0,0,109,97, 110,97,103,101,114,45,...>>,%Mongo.Cursor {batchSize:0,collection:%Mongo.Collection {db:%Mongo.Db {auth:{" admin"," edd5404c4f906060b125688e26ffb281"},mongo:%Mongo.Server {host:' db-stage.member0.mongolayer.com',id_prefix:57602,mode :: passive, opts:%{},port:27017,socket:#port< 0.27099>,timeout:6000},name:" db-stage",opts:%{mode :: passive,timeout:6000} },name:" jobs",opts:%{}},exhausted:false,response:%Mongo.Response {buffer:<<<& 188,14,0,0,7,95,105 ,100,0,82,110,129,221,102,160,249,201,109,0,137,242,4,95,115,108,117,103,115,0,45,0,0 ,0,2,48,0,33,0,0,0,110,101,116,97,...>>,cursorID:3958284337526732701,decoder:& Mongo.Response.bson _decode / 1,nbdoc:101,requestID:67280413,startingFrom:0}}}})       (elixir)lib / stream.ex:1020:Stream.do_resource / 5       (elixir)lib / enum.ex:1731:Enum.take / 2

我很难过。有任何想法吗? 谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

荡!新秀错误。

:halt -> {:halt, {cont, therest, c}}应为_ -> {:halt, z}fn(:halt, resp) -> resp end应为fn(resp) -> resp end

除了后续功能一天半之外,我一直在为所有人做好准备。

对其他新秀的更多解释......

  • next_fun()中的最后一个选项应该_,以便捕获其他"不良行为"而不只是{:halt}
  • after_fn()只期望1个arg,在上面的代码中将是next_fun()的最后一个选项中的z元组。我们不希望看到:haltz,只看z

想要真正的专家输入。