长生不老药流蒙多德失败



我正在使用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, <<90, 44, 0, 0, 7, 95, 105, 100, 0, 82, 110, 129, 221, 102, 160, 249, 201, 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: :p assive, opts: %{}, port: 27017, socket: #Port<0.27099>, timeout: 6000}, name: "db-stage", opts: %{mode: :p assive, 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, 114, 101, 116, 97, ...>>, cursorID: 3958284337526732701, 解码器: &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

我被难住了。有什么想法吗?感谢您的帮助

Dang!菜鸟错误。

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

除了一天半的术后功能,我一直在做所有事情。

给其他新秀多一点解释...

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

希望有真正的专家意见。

相关内容

  • 没有找到相关文章

最新更新